using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int t = 3;
            
            int n = int.Parse(Console.ReadLine());
            int[] r = new  int[n];
            int[] c = new int[n];

            string[] h = new string[2];
            string[] x = new string[n];
            int[] z = new int[n];
            
            for (int i = 0; i < n; i++)
            {
                x[i] = Console.ReadLine();
            }

            for (int j = 0; j < n; j++)
                h = x[j].Split(' ');

            for (int u = 0; u < n; u++)
                r[u] = int.Parse(h[0]);

            for (int u = 0; u < n; u++)
                c[u] = int.Parse(h[1]);

           
            if (n > 2)
            {
                for (int i = 0; i < n; i++)
                    for (int j = 0; j < n; j++)
                        if (r[i] == r[j])
                            t = 0;
            }
            else
                if (n == 2)
                    if (r[0] != r[1] || c[0] != c[1])
                        t = 1;
                    else
                        t = 0;
                else if(n == 1)
                    t = 0;
            Console.WriteLine(t);
            Console.ReadLine();   
        }

    }
}