import java.util.*;
public class tournamentmatchmaking_xiaowuc1 {
  static final int NUMP = 15;
  static final int SHIFT = 15;
  static final int MASK = (1<<SHIFT)-1;
  static int[][] roles;
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    roles = new int[n][];
    int[] even = new int[n]; int evenc = 0;
    int[] odd = new int[n]; int oddc = 0;
    for(int i = 0; i < n; i++) {
      int k = sc.nextInt();
      roles[i] = new int[k];
      if(k%2==0) even[evenc++] = i;
      else odd[oddc++] = i;
      for(int a = 0; a < k; a++) {
        int x = sc.nextInt()-1;
        int y = sc.nextInt()-1;
        roles[i][a] = (x << SHIFT) | (y);
      }
    }
    int ret = 0;
    boolean[][] outer = new boolean[evenc][oddc];
    for(int i = 0; i < evenc; i++) for(int j = 0; j < oddc; j++) {
      if(roles[even[i]].length + roles[odd[j]].length != NUMP) continue;
      boolean[][] inner = new boolean[NUMP][NUMP];
      int idx = 0;
      for(int a: roles[even[i]]) {
        inner[idx][a&MASK] = true;
        inner[idx][(a>>SHIFT)] = true;
        idx++;
      }
      for(int a: roles[odd[j]]) {
        inner[idx][a&MASK] = true;
        inner[idx][(a>>SHIFT)] = true;
        idx++;
      }
      if(match(inner, new int[NUMP], new int[NUMP]) == NUMP) outer[i][j] = true;
    }
    System.out.println(match(outer, new int[evenc], new int[oddc]));
  }
  public static boolean match(int i, boolean[][] w, int[] mr, int[] mc, int[] seen, int seeniter) {
    for(int j = 0; j < w[i].length; j++) {
      if(w[i][j] && seen[j] != seeniter) {
        seen[j] = seeniter;
        if(mc[j] < 0) {
          mr[i] = j;
          mc[j] = i;
          return true;
        }
        seen[j] = -1;
      }
    }
    for(int j = 0; j < w[i].length; j++) {
      if(w[i][j] && seen[j] != seeniter) {
        seen[j] = seeniter;
        if(match(mc[j], w, mr, mc, seen, seeniter)) {
          mr[i] = j;
          mc[j] = i;
          return true;
        }
      }
    }
    return false;
  }
  public static int match(boolean[][] w, int[] mr, int[] mc) {
    if(mr.length == 0 || mc.length == 0) return 0;
    Arrays.fill(mr, -1);
    Arrays.fill(mc, -1);
    int ct = 0;
    int[] dp = new int[w[0].length];
    for(int i = 0; i < w.length; i++) {
      if(match(i, w, mr, mc, dp, i+1)) ct++;
    }
    return ct;
  }
}
