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.io.PrintWriter;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Queue;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class Main {
	class node {
	    int v, w;
	    node() {}
	    node(int v, int w) {
	    	this.v = v; this.w = w;
	    }
	}
	ArrayList<node>[] g = new ArrayList[N];
	int[] ss = new int[N];
	int [][] dp = new int[N][2];
	int num, n;
	void go(int u, int f, int x) {
	    num += x;
	    ss[u] = ss[f] + x;
	    int sz = g[u].size();
	    for(int i = 0; i < sz; i++) {
	        int v = g[u].get(i).v;   if(v == f) continue;
	        int w = g[u].get(i).w;
	        go(v, u, w);
	    }
	}
	void dfs(int u, int f, int x) {
	    if(f == 0) 
	        dp[u][0] = dp[u][1] = 0;
	    else {
	        dp[u][1] = dp[f][1] + x;
	        dp[u][0] = min(dp[f][0], dp[f][1]) ;
	        if(x==0)dp[u][0]++;
	    }
	    int sz = g[u].size();
	    for(int i = 0; i < sz; i++) {
	        int v = g[u].get(i).v;
	        int w = g[u].get(i).w;
	        if(v == f) continue;
	        dfs(v, u, w);
	    }
	}
	void work() throws Exception {
	    n = Int();
	    for(int i = 1; i <= n; i++) g[i] = new ArrayList();
	    for(int i = 1, u, v; i < n; i++) {
	        u = Int(); v = Int();
	        g[u].add(new node(v, 0));
	        g[v].add(new node(u, 1));
	    }
	    int ans = inf;
	    for(int i = 1; i <= n; i++) {
	        ss[i] = 0;
	        num = 0;
	        go(i, 0, 0);
	        dfs(i, 0, 0);
	        for(int j = 1; j <= n; j++) ans = min(ans, num - ss[j] + min(dp[j][0], dp[j][1]));
	    }
	    out.println(ans);
	}

	public static void main(String[] args) throws Exception {
		Main wo = new Main();
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		// in = new BufferedReader(new InputStreamReader(new FileInputStream(new
		// File("input.txt"))));
		// out = new PrintWriter(new File("output.txt"));
		wo.work();
		out.close();
	}

	static int N = 3005;
	static int M = N*2;
	DecimalFormat df = new DecimalFormat("0.0000");
	static int inf = (int) 1e9;
	static long inf64 = (long) 1e18;
	static double eps = 1e-8;
	static double Pi = Math.PI;
	static int mod = (int) 1e9 + 7;

	private String Next() throws Exception {
		while (str == null || !str.hasMoreElements())
			str = new StringTokenizer(in.readLine());
		return str.nextToken();
	}

	private int Int() throws Exception {
		return Integer.parseInt(Next());
	}

	private long Long() throws Exception {
		return Long.parseLong(Next());
	}

	private double Double() throws Exception {
		return Double.parseDouble(Next());
	}

	StringTokenizer str;
	static Scanner cin = new Scanner(System.in);
	static BufferedReader in;
	static PrintWriter out;
/*
	 class Edge{ 
		 int from, to, dis, nex; 
		 Edge(){} 
		 Edge(int from, int to, int dis, int nex){ 
			 this.from = from; this.to = to; this.dis = dis; this.nex = nex; 
			 } 
		 } 
	 Edge[] edge = new Edge[M<<1]; 
	 int[] head = new int[N]; int edgenum; 
	 void init_edge(){
		 for(int i = 0; i < N; i++)head[i] = -1; 
		 edgenum = 0;}
	 void add(int u, int v, int dis){ 
		 edge[edgenum] = new Edge(u, v, dis, head[u]); 
		 head[u] = edgenum++;
	}/**/
	int upper_bound(int[] A, int l, int r, int val) {// upper_bound(A+l,A+r,val)-A;
		int pos = r;
		r--;
		while (l <= r) {
			int mid = (l + r) >> 1;
			if (A[mid] <= val) {
				l = mid + 1;
			} else {
				pos = mid;
				r = mid - 1;
			}
		}
		return pos;
	}

	int lower_bound(int[] A, int l, int r, int val) {// upper_bound(A+l,A+r,val)-A;
		int pos = r;
		r--;
		while (l <= r) {
			int mid = (l + r) >> 1;
			if (A[mid] < val) {
				l = mid + 1;
			} else {
				pos = mid;
				r = mid - 1;
			}
		}
		return pos;
	}

	int Pow(int x, int y) {
		int ans = 1;
		while (y > 0) {
			if ((y & 1) > 0)
				ans *= x;
			y >>= 1;
			x = x * x;
		}
		return ans;
	}

	double Pow(double x, int y) {
		double ans = 1;
		while (y > 0) {
			if ((y & 1) > 0)
				ans *= x;
			y >>= 1;
			x = x * x;
		}
		return ans;
	}

	int Pow_Mod(int x, int y, int mod) {
		int ans = 1;
		while (y > 0) {
			if ((y & 1) > 0)
				ans *= x;
			ans %= mod;
			y >>= 1;
			x = x * x;
			x %= mod;
		}
		return ans;
	}

	long Pow(long x, long y) {
		long ans = 1;
		while (y > 0) {
			if ((y & 1) > 0)
				ans *= x;
			y >>= 1;
			x = x * x;
		}
		return ans;
	}

	long Pow_Mod(long x, long y, long mod) {
		long ans = 1;
		while (y > 0) {
			if ((y & 1) > 0)
				ans *= x;
			ans %= mod;
			y >>= 1;
			x = x * x;
			x %= mod;
		}
		return ans;
	}

	int gcd(int x, int y) {
		if (x > y) {
			int tmp = x;
			x = y;
			y = tmp;
		}
		while (x > 0) {
			y %= x;
			int tmp = x;
			x = y;
			y = tmp;
		}
		return y;
	}

	int max(int x, int y) {
		return x > y ? x : y;
	}

	int min(int x, int y) {
		return x < y ? x : y;
	}

	double max(double x, double y) {
		return x > y ? x : y;
	}

	double min(double x, double y) {
		return x < y ? x : y;
	}

	long max(long x, long y) {
		return x > y ? x : y;
	}

	long min(long x, long y) {
		return x < y ? x : y;
	}

	int abs(int x) {
		return x > 0 ? x : -x;
	}

	double abs(double x) {
		return x > 0 ? x : -x;
	}

	long abs(long x) {
		return x > 0 ? x : -x;
	}

	boolean zero(double x) {
		return abs(x) < eps;
	}

	double sin(double x) {
		return Math.sin(x);
	}

	double cos(double x) {
		return Math.cos(x);
	}

	double tan(double x) {
		return Math.tan(x);
	}

	double sqrt(double x) {
		return Math.sqrt(x);
	}
}
  	  	   									 	 	 			   		