import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; public class Main { static int n; static List> list; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); n = Integer.parseInt(br.readLine()); int m = 200000; list = new ArrayList<>(m); for (int i = 0; i < m; i++) { list.add(new HashSet<>()); } int[] in = new int[m]; int[] out = new int[m]; for (int i = 0; i < n; i++) { String[] sa = br.readLine().split(" "); Hen h = new Hen(); h.a = Integer.parseInt(sa[0]) - 1; h.b = Integer.parseInt(sa[1]) - 1; list.get(h.a).add(h); out[h.a]++; in[h.b]++; } br.close(); int s = -1; int t = -1; for (int i = 0; i < m; i++) { if (in[i] != out[i]) { if (Math.abs(in[i] - out[i]) > 1) { System.out.println(0); return; } if (in[i] + 1 == out[i]) { if (s == -1) { s = i; } else { System.out.println(0); return; } } else { if (t == -1) { t = i; } else { System.out.println(0); return; } } } } if (s == -1 && t == -1) { System.out.println(n); } else { System.out.println(1); } } static class Hen { int a, b; } }