using System;

namespace Zlatnici
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[,] mat = new int[n, n];
            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                int x = int.Parse(s[0]);
                int y = int.Parse(s[1]);
                mat[x-1, y-1] = 1;
            }
            if (n == 1)
            {
                Console.WriteLine(0);
                return;
            }
            if (n == 2)
            {
                if ((mat[0, 0] == 1 && mat[1, 1] == 1) || (mat[1, 0] == 1 && mat[0, 1] == 1)) Console.WriteLine(0);
                else Console.WriteLine(1);
                return;
            }
            int brbr = 0;
            for (int i = 0; i < n; i++)
            {
                int br1 = 0;
                int br2 = 0;
                for (int j = 0; j < n; j++)
                {
                    if (mat[i,j] == 1)
                    {
                        br1++;
                    }   
                    if (mat[j,i] == 1)
                    {
                        br2++;
                    }
                }
                if (br1 > 1 || br2 > 1) brbr = 1;
            }
            if (brbr == 0)
            {
                Console.WriteLine(0);
                return;
            }
        }
    }
}