#include int abs(int n) { if (n < 0) n *= -1; return n; } int main() { int n; scanf("%d", &n); int i; int h[200005], w[200005]; for (i = 0; i < n; i++) scanf("%d %d", &h[i], &w[i]); int in[200005], out[200005]; for (i = 0; i < 200005; i++) in[i] = out[i] = 0; for (i = 0; i < n; i++) { in[w[i]]++; out[h[i]]++; } int cnt = 0; for (i = 0; i < 200005; i++) { if (abs(in[i] - out[i]) > 1) cnt += 10; else cnt += abs(in[i] - out[i]); } if (cnt > 2) { printf("0\n"); return 0; } if (cnt == 2) { printf("1\n"); return 0; } cnt = 0; for (i = 0; i < 200005; i++) if (in[i] > 0) cnt++; printf("%d\n", cnt); return 0; }