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

namespace ConsoleApplication28
{
    class Program
    {
        static long zbirvrsta(long[,] x, long n)
        {
            long s = 0;
            for (long i = 0; i < n; i++)
            {
                s = x[0, i] + s;
            }
            return s;
        }
        static long zbirkolona(long[,] x, long n)
        {
            long s = 0;
            for (long i = 0; i < n; i++)
            {
                s = x[i, 0] + s;
            }
            return s;
        }
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long[,] x = new long[n, n];
            for (long i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                x[Convert.ToInt64(s[0])-1, Convert.ToInt64(s[1])-1] = 1;
            }
            bool a = false;
            for (int i = 0; i < n; i++)
            {
                if (zbirkolona(x, n) == 1 && zbirvrsta(x, n) == 1) a = true;
                else
                {
                    a = false;
                    break;
                }
            }
            if (a) Console.WriteLine(0);

        }
    }
}