#include #include int main() { int i, N, H, W, num[2][200001] = {}, ans = 0, count = 0; scanf("%d", &N); for (i = 1; i <= N; i++) { scanf("%d %d", &H, &W); if (H == W) continue; num[0][H]++; num[1][W]++; } for (i = 1; i <= 200000; i++) { if (num[0][i] == num[1][i]) { if (num[0][i] > 0) count++; continue; } else if (abs(num[0][i] - num[1][i]) == 1) ans++; else { ans = -1; break; } } if (ans == 0) printf("%d\n", count); else if (ans == 2) printf("1\n"); else printf("0\n"); fflush(stdout); return 0; }