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

namespace Zad4
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = new int[n-1];
            int[] y = new int[n-1];
            for(int i=0;i<n-1;i++)
            {
                string p = Console.ReadLine();
                string[] sp = p.Split(' ');
                x[i] = Convert.ToInt32(sp[0]);
                y[i] = Convert.ToInt32(sp[1]);

            }
            bool ponavljanje = false;
            bubbleSort(x);
            bubbleSort(y);
            for(int j=0;j<n-2;j++)
            {
                if(x[j]==x[j+1]||y[j]==y[j+1])
                {
                    ponavljanje = true;
                }
            }
            if (ponavljanje == true)
            {
                Console.WriteLine("2");
            }
            else
            {
                Console.WriteLine("1");
            }
        }
        static void bubbleSort(int[] niz)
        {
            int n = niz.Length;
            for (int i = 0; i < n - 1; i++)
                for (int j = 0; j < n - i - 1; j++)
                    if (niz[j] > niz[j + 1])
                    {
                        int pom = niz[j];
                        niz[j] = niz[j + 1];
                        niz[j + 1] = pom;
                    }
        }
    }
}