#include <iostream>

int main() {
  long n;
  std::cin >> n;
  long r[n], c[n];

  for (long i = 0; i < n; i++) {
    std::cin >> r[i] >> c[i];
    if (r == c) t = 0;
    else t = n - 1;
  }

  if (n == 1) t = 0;
  if (n == 2) {
    if (r[1] == r[2] || c[1] == c[2]) t = 1;
    else t = 0;
  }
  std::cout << t;
  return 0;
}