You must have heard of the two brothers dreaming of ruling the world. With all their previous plans failed, this time they decided to cooperate with each other in order to rule the world. 

As you know there are n countries in the world. These countries are connected by n - 1 directed roads. If you don't consider direction of the roads there is a unique path between every pair of countries in the world, passing through each road at most once. 

Each of the brothers wants to establish his reign in some country, then it's possible for him to control the countries that can be reached from his country using directed roads. 

The brothers can rule the world if there exists at most two countries for brothers to choose (and establish their reign in these countries) so that any other country is under control of at least one of them. In order to make this possible they want to change the direction of minimum number of roads. Your task is to calculate this minimum number of roads.

Input

The first line of input contains an integer n (1 ≤ n ≤ 3000). Each of the next n - 1 lines contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi) saying there is a road from country ai to country bi.

Consider that countries are numbered from 1 to n. It's guaranteed that if you don't consider direction of the roads there is a unique path between every pair of countries in the world, passing through each road at most once.

Output

In the only line of output print the minimum number of roads that their direction should be changed so that the brothers will be able to rule the world.

Examples

Input

4
2 1
3 1
4 1


Output

1


Input

5
2 1
2 3
4 3
4 5


Output

0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class CodeB 
{
	static class Scanner
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		
		public String nextLine()
		{
			try
			{
				return br.readLine();
			}
			catch(Exception e)
			{
				throw(new RuntimeException());
			}
		}
		
		public String next()
		{
			while(!st.hasMoreTokens())
			{
				String l = nextLine();
				if(l == null)
					return null;
				st = new StringTokenizer(l);
			}
			return st.nextToken();
		}
		
		public int nextInt()
		{
			return Integer.parseInt(next());
		}
		
		public long nextLong()
		{
			return Long.parseLong(next());
		}
		
		public double nextDouble()
		{
			return Double.parseDouble(next());
		}
		
		public int[] nextIntArray(int n)
		{
			int[] res = new int[n];
			for(int i = 0; i < res.length; i++)
				res[i] = nextInt();
			return res;
		}
		
		public long[] nextLongArray(int n)
		{
			long[] res = new long[n];
			for(int i = 0; i < res.length; i++)
				res[i] = nextLong();
			return res;
		}
		
		public double[] nextDoubleArray(int n)
		{
			double[] res = new double[n];
			for(int i = 0; i < res.length; i++)
				res[i] = nextLong();
			return res;
		}
		public void sortIntArray(int[] array)
		{
			Integer[] vals = new Integer[array.length];
			for(int i = 0; i < array.length; i++)
				vals[i] = array[i];
			Arrays.sort(vals);
			for(int i = 0; i < array.length; i++)
				array[i] = vals[i];
		}
		
		public void sortLongArray(long[] array)
		{
			Long[] vals = new Long[array.length];
			for(int i = 0; i < array.length; i++)
				vals[i] = array[i];
			Arrays.sort(vals);
			for(int i = 0; i < array.length; i++)
				array[i] = vals[i];
		}
		
		public void sortDoubleArray(double[] array)
		{
			Double[] vals = new Double[array.length];
			for(int i = 0; i < array.length; i++)
				vals[i] = array[i];
			Arrays.sort(vals);
			for(int i = 0; i < array.length; i++)
				array[i] = vals[i];
		}
	}
	
	static Nodo centroActual;
	
	static class Nodo
	{
		ArrayList <Arista> aristas = new ArrayList <Arista> ();
		ArrayList <Integer> subArboles = new ArrayList <Integer> ();
		int totalParcial = 0;
		boolean termino = false;
		
		int calcularMejorEscogida(Nodo padre)
		{
			int minimo = calcularCostoSubArbol(-1);
			for(Arista a : aristas)
				if(a.otro != padre)
					minimo = Math.min(minimo, a.otro.calcularMejorEscogida(this));
			return minimo;
		}
		
		int calcularCostoSubArbol(int idArista)
		{
			if(this == centroActual)
				return 0;
			if(subArboles.isEmpty())
			{
				for(int i = 0; i < aristas.size(); i++)
					subArboles.add(null);
				for(int i = 0; i < aristas.size(); i++)
				{
					if(i == idArista)
						continue;
					Arista actual = aristas.get(i);
					subArboles.set(i, (actual.invertida ? 1 : 0) + actual.otro.calcularCostoSubArbol(actual.idOpuesto));
					totalParcial += subArboles.get(i);
				}
				return totalParcial;
			}
			else
			{
				if(idArista >= 0 && subArboles.get(idArista) == null)
					return totalParcial;
				if(!termino)
				{
					for(int i = 0; i < aristas.size(); i++)
					{
						if(subArboles.get(i) == null)
						{
							Arista actual = aristas.get(i);
							subArboles.set(i, (actual.invertida ? 1 : 0) + actual.otro.calcularCostoSubArbol(actual.idOpuesto));
							totalParcial += subArboles.get(i);
						}
					}
					termino = true;
				}
				return totalParcial - (idArista < 0 ? 0 : subArboles.get(idArista));
			}
		}
		
		void limpiar()
		{
			subArboles.clear();
			termino = false;
			totalParcial = 0;
		}
		
		int calcularSolucion()
		{
			if(aristas.size() <= 1)
				return Integer.MAX_VALUE;
			centroActual = this;
			for(Nodo n : nodos)
				n.limpiar();
			class Entrada implements Comparable <Entrada>
			{
				int costo;
				int ahorro;
				int escogiendo;
				boolean opuesta;
				
				@Override
				public int compareTo(Entrada o) 
				{
					if(ahorro == o.ahorro)
					{
						if(opuesta == o.opuesta)
							return 0;
						else if(!opuesta)
							return -1;
						else
							return 1;
					}
					return o.ahorro - ahorro;
				}
			}
			Entrada mejorUno = null;
			Entrada mejorDos = null;
			int totalCostos = 0;
			for(Arista a : aristas)
			{
				Entrada nueva = new Entrada();
				nueva.costo = (a.invertida ? 1 : 0) + a.otro.calcularCostoSubArbol(a.idOpuesto);
				nueva.escogiendo = a.otro.calcularMejorEscogida(this);
				nueva.ahorro = nueva.costo - nueva.escogiendo;
				nueva.opuesta = a.invertida;
				totalCostos += nueva.costo;
				if(mejorUno == null)
					mejorUno = nueva;
				else if(mejorDos == null)
					mejorDos = nueva;
				else
				{
					if(nueva.compareTo(mejorUno) < 0)
					{
						mejorDos = mejorUno;
						mejorUno = nueva;
					}
					else if(nueva.compareTo(mejorDos) < 0)
						mejorDos = nueva;
				}
			}
			totalCostos -= mejorUno.ahorro;
			totalCostos -= mejorDos.ahorro;
			if(!mejorUno.opuesta || !mejorDos.opuesta)
				totalCostos--;
			return totalCostos;
		}
	}
	
	static class Arista
	{
		Nodo otro;
		boolean invertida;
		int idOpuesto;
		
		public Arista(Nodo o, boolean in, int id)
		{
			otro = o;
			invertida = in;
			idOpuesto = id;
		}
	}
	
	static Nodo[] nodos;
	
	static void agregarArista(int a, int b)
	{
		int idA = nodos[a].aristas.size();
		int idB = nodos[b].aristas.size();
		nodos[a].aristas.add(new Arista(nodos[b], false, idB));
		nodos[b].aristas.add(new Arista(nodos[a], true, idA));
	}
	
	public static void main(String[] args)
	{
		Scanner sc = new Scanner();
		int n = sc.nextInt();
		nodos = new Nodo[n];
		for(int i = 0; i < n; i++)
			nodos[i] = new Nodo();
		for(int i = 0; i < n - 1; i++)
			agregarArista(sc.nextInt() - 1, sc.nextInt() - 1);
		int mejor = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++)
			mejor = Math.min(mejor, nodos[i].calcularSolucion());
		System.out.println(mejor == Integer.MAX_VALUE ? 0 : mejor);
	}
}