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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	InputStreamReader inp = new InputStreamReader(System.in);
	BufferedReader in = new BufferedReader(inp);
	boolean test = false;

	String[] inData = { 
			
//			"1",
//			"2000 1000000000",
//			"0 10",
//			"1 10",
//			"1 10"
			
		"3",
		"0 1",
		"0 10",
		"0 100"
	};
	
	int[][] vals;
	
	public Main() throws Throwable {
		
		int itemCount = readInt();
		
		vals = new int[itemCount][2];
		for (int i = 0; i < itemCount; i++) {
			vals[i] = readInts();
			vals[i][0] ++;
		}
		
//		dp[m][s] = the minimal cost of a subset of items that you choose among the first m items so that the sum of (t_i+1) >= s (here i runs over the indices of the chosen items). 
//		The answer is dp[n][n]
		
		long[][] dp = new long[itemCount+1][itemCount+1];
		
		for (long[] is : dp) {
			Arrays.fill(is, Long.MAX_VALUE - 5000000001L);
		}
		
		dp[0][0] = 0;
		
		for (int i = 1; i < dp.length; i++) {
			for (int j = 0; j < dp.length; j++) {
				int nextItemPrice = vals[i-1][1];
				int nextItemTime = vals[i-1][0];
				
				long minPrice = dp[i-1][j];
				
					if( j-nextItemTime  >= 0){
						long newAlt = dp[i-1][j-nextItemTime] + nextItemPrice;
						minPrice = Math.min(minPrice, newAlt);	
					}  else {
						minPrice = Math.min(minPrice, nextItemPrice);
					}
				dp[i][j] = minPrice;
			}
		}
		
		System.out.println(dp[itemCount][itemCount]);
	}

	private int go(boolean[] chosenItems, int curPrice, int bestVal) {
		
		int totTime = 0;
		int totPrice = 0;
		
		int stealItems = 0;
		
		for (int i = 0; i < chosenItems.length; i++) {
			if(chosenItems[i]){
				totTime += vals[i][0] ;
				totPrice += vals[i][1];
			} else {
				stealItems ++;
			}
		}
		
		if(bestVal < totPrice){
			return bestVal;
		}
		
		if(totTime >= stealItems ){
			return Math.min(bestVal, totPrice);
		} else {
			for (int i = 0; i < chosenItems.length; i++) {
				if(!chosenItems[i]){
					chosenItems[i] = true;
					bestVal = go(chosenItems, curPrice, bestVal);
					chosenItems[i] = false;
				}
			}
		}
		return bestVal;
	}

	static int id = -1;

	public int[] readInts() throws IOException {
		String[] split = readLine().split(" ");
		int[] ret = new int[split.length];
		for (int i = 0; i < split.length; i++) {
			ret[i] = Integer.parseInt(split[i]);
		}
		return ret;
	}

	public int readInt() throws IOException {
		return Integer.parseInt(readLine());
	}

	public String readLine() throws IOException {
		id++;
		if (test){
			return inData[id];
		} else {
			return in.readLine();
		}	
	}

	public static void main(String[] args) throws Throwable {
		new Main();
	}
}