// Arup Guha
// 4/27/2024
// Solution to Kattis Problem: Keyboards in Concert

import java.util.*;

public class keyboardsinconcert {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nInst = stdin.nextInt();
		int nNotes = stdin.nextInt();
		
		// notes[i] will store the instrument numbers that play note i.
		HashSet<Integer>[] notes = new HashSet[1001];
		for (int i=0; i<1001; i++)
			notes[i] = new HashSet<Integer>();
		
		// Go through each instrument.
		for (int i=0; i<nInst; i++) {
		
			// Number of notes that instrument i can play.
			int n = stdin.nextInt();
			
			// For each node, add instrument i as an instrument that can play it.
			for (int j=0; j<n; j++) {
				int mynote = stdin.nextInt();
				notes[mynote].add(i);
			}
		}
		
		// Read in the song.
		int[] song = new int[nNotes];
		for (int i=0; i<nNotes; i++)
			song[i] = stdin.nextInt();
			
		// dp[i][j] = min # changes
		int[][] dp = new int[nNotes][nInst];
		
		// Initially, we say that this isn't possible.
		for (int i=0; i<nInst; i++)
			dp[0][i] = nNotes+1;
			
		// These are the instruments that we can start the song on.
		for (Integer x: notes[song[0]])
			dp[0][x] = 0;
		
		// Get the best answer for ending at note i.
		for (int i=1; i<nNotes; i++) {
			
			// Default values.
			for (int j=0; j<nInst; j++)
				dp[i][j] = nNotes+1;
			
			// Get best previous answer.
			int prevMin = nNotes+1;
			for (int j=0; j<nInst; j++)
				prevMin = Math.min(prevMin, dp[i-1][j]);
			
			// loop through the instruments that can play this note.
			for (Integer x: notes[song[i]]) {
				
				// Stay on this instrument for this note.
				dp[i][x] = Math.min(dp[i][x], dp[i-1][x]);
				
				// Change from the old minimum to this instrument.
				dp[i][x] = Math.min(dp[i][x], prevMin+1);
			}
		}
		
		// Answer is best in the last column.
		int res = dp[nNotes-1][0];
		for (int j=1; j<nInst; j++)
			res = Math.min(res, dp[nNotes-1][j]);
		
		// Ta da!
		System.out.println(res);
	}
}