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.*;
import java.util.*;
public class Answer19B{
    public static void main(String[] args){
	BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
	new Kai(reader).solve();
    }
}
class Kai{
    BufferedReader reader;
    public Kai(BufferedReader reader){
	this.reader=reader;
    }
    public void solve(){
	//TODO
	int n=to_i(read());
	int[] t=new int[n];
	long[] c=new long[n];
	long sum=0;
	for(int i=0;i<n;i++){
	    String[] tmp=read().split(" ");
	    t[i]=to_i(tmp[0]);
	    c[i]=to_i(tmp[1]);
	    sum+=c[i];
	}
	long[][] dp =new long[n+1][n+1+n];
	for(int i=0;i<n+1;i++)Arrays.fill(dp[i],-1);
	dp[0][n]=0;
	for(int i=0;i<n;i++){
	    for(int j=0;j<2*n+1;j++){
		if(dp[i][j]!=-1){
		    //get
		    dp[i+1][j-1]=Math.max(dp[i][j]+c[i],dp[i+1][j-1]);
		    //remove
		    int num=j+t[i];
		    if(num>=2*n)num=2*n;
		    dp[i+1][num]=Math.max(dp[i][j],dp[i+1][num]);
		}
	    }
	}
	long max=0;
	for(int i=n;i<2*n;i++){
	    max=Math.max(dp[n][i],max);
	}
	println(sum-max);
    }
    public String read(){
	String s=null;
	try{
	    s=reader.readLine();
	}catch(IOException e){
	    e.printStackTrace();
	}
	return s;
    }
    public int to_i(String s){
	return Integer.parseInt(s);
    }
    public long to_l(String s){
	return Long.parseLong(s);
    }
    public void print(Object s){
	System.out.print(s);
    }
    public void println(Object s){
	System.out.println(s);
    }
    public void debug(Object s){
	System.err.print(s);
    }
    public void debugln(Object s){
	System.err.println(s);
    }
    public void debug(Object[] s){
	System.err.print(Arrays.deepToString(s));
    }
    public void debugln(Object[] s){
	System.err.print(Arrays.deepToString(s));
    }
}