Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. To steal one item Bob needs exactly 1 second. What is the minimum amount of money that Bob will have to pay to the checkout assistant? Remember, please, that it is Bob, who determines the order of items for the checkout assistant.

Input

The first input line contains number n (1 ≤ n ≤ 2000). In each of the following n lines each item is described by a pair of numbers ti, ci (0 ≤ ti ≤ 2000, 1 ≤ ci ≤ 109). If ti is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i.

Output

Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.

Examples

Input

4
2 10
0 20
1 5
1 3


Output

8


Input

3
0 1
0 10
0 100


Output

111
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
import java.math.*;

public class Main implements Runnable {
	BufferedReader in;  
	StringTokenizer st = new StringTokenizer("");
	long [] c; int[] t;
	
	public static void main(String [] args) throws Exception {
		new Thread(new Main()).start();
	}

	 void printExit(String s) {
		System.out.println(s);
		System.exit(0);
	}

	public void run() {
		try {
			Locale.setDefault(Locale.US);
			in = new BufferedReader(new InputStreamReader(System.in));

			int n = nextInt();
			t = new int[n];
			c = new long[n];
			for (int i = 0; i < n; i++) {
				t[i] = nextInt();
				c[i] = nextInt();
			}

			int size = 2 * (n + 5);
			long [] mc = new long [size];

			Arrays.fill(mc, -1);
			mc[n] = 0;
			for (int i = 0; i < n; i++) {
				long [] next = new long[size];
				Arrays.fill(next, -1);
				for (int j = 0; j < size; j++)
					if (mc[j] != -1) {
						//buy
						int ind = Math.min(size - 1, j + t[i]);
						if (next[ind] == -1 || next[ind] > mc[j] + c[i])
							next[ind] = mc[j] + c[i];
						//steal
						if (j == 0) continue;
						if (next[j - 1] == -1 || next[j - 1] > mc[j])
							next[j - 1] = mc[j];
					}
				for (int t = 0; t < size; t++)
					mc[t] = next[t];
			}

			long ans = Long.MAX_VALUE;
			for (int i = n; i < size; i++)
				if (mc[i] != -1)
					ans = Math.min(ans, mc[i]);
		
			System.out.println(ans);
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}

	 boolean seekForToken() {
 		try {
			while (!st.hasMoreTokens()) {
				String s = in.readLine();
				if (s == null) {
				 	return false;
				}
			 	st = new StringTokenizer(s);
			}
			return true;
		}
		catch (IOException e) {
		 	e.printStackTrace();
		 	return false;
		}
 	}

 	 int nextInt() {
		return Integer.parseInt(nextToken());
 	}

 	 long nextLong() {
		return Long.parseLong(nextToken());
 	}

 	 double nextDouble() {
		return Double.parseDouble(nextToken());
 	}

 	 BigInteger nextBigInteger() {
 	 	return new BigInteger(nextToken());
 	}

 	 String nextToken() {
 	 	seekForToken();
 	 	return st.nextToken();
 	}

}
