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

namespace ConsoleApp3
{
    class Program
    {
        public static int koji(bool[,] niz)
        {
            for (int i = 0; i < niz.Length; i++)
            {
                if (niz.Length<=0)
                {
                    for (int j = 0; j < niz.Length; j++)
                    {
                        bool flag = false;
                        if (niz[i, j] == false)
                        {
                            flag = true;
                        }
                        else
                        {
                            flag = false;
                            break;
                        }
                    }
                }
                
            }
            if (niz[1,0] == true)
            {
                return 2;
            }
            else
            {
                return 0;
            }
        }
        static void Main(string[] args)
        {
            string[] tokens;
            string inpt = Console.ReadLine();
            long N = long.Parse(inpt);
            bool[,] niz1 = new bool[N, N];
            for (int i = 0; i < N; i++)
            {
                tokens = Console.ReadLine().Split();
                niz1[int.Parse(tokens[0])-1, int.Parse(tokens[1]) - 1] = true;
            }
            
            int poz = 5;
            int trenuci=0;
            for (int i = 0; i < N; i++)
            {
                if (poz == koji(niz1))
                {
                    trenuci++;
                }
            }

            Console.WriteLine(koji(niz1).ToString());
        }
    }
}