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

namespace JAG
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            int[] b = new int[n];
            for (int i = 0; i < n - 1; i++) 
            {
                string[] s = Console.ReadLine().Split();
                a[i] = int.Parse(s[0]);
                b[i] = int.Parse(s[1]);
            }
            int x = 0;
            for (int i = 0; i < n - 2; i++) 
            {
                if (a[i + 1] == b[i]) x++;
            }
            if (x == n - 2 && n % 2 == 0) Console.WriteLine(n - 3);
            else if (x == n - 2 && n % 2 != 0) Console.WriteLine(n - 2);
        }
    }
}