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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main implements Runnable {
	private boolean _ReadFromFile = false;//System.getProperty("ONLINE_JUDGE") == null;
	private boolean _WriteToFile = false;
	static final String TASK_ID = "in";
	static final String IN_FILE = TASK_ID + ".in";
	static final String OUT_FILE = TASK_ID + ".out";
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	class Entry {
		int time, cost;
		public Entry(int time, int cost) {
			this.time = time;
			this.cost = cost;
		}
	}

	private void core() throws Exception {
		int n = nextInt();
		Entry[] all = new Entry[n];
		for (int i = 0; i < all.length; i++) {
			all[i] = new Entry(nextInt(), nextInt());
		}
		long[][] f = new long[n+1][n+n+1];
		int offset = n;
		for (long[] ls : f) {
			Arrays.fill(ls, Long.MAX_VALUE);
		}
		
		f[0][0 + offset] = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < f[i].length; j++) {
				if (f[i][j] != Long.MAX_VALUE) {
					f[i+1][j-1] = Math.min(f[i+1][j-1], f[i][j]);
					int nj = j + all[i].time;
					if (nj >= f[i].length) nj = f[i].length - 1;
					f[i+1][nj] = Math.min(f[i+1][nj], f[i][j] + all[i].cost);
				}
			}
		}
		
		long res = Long.MAX_VALUE;
		for (int j = offset; j < f[0].length; j++) {
			if (f[n][j] < res)
				res = f[n][j];
		}
		
		writer.println(res);
	}
	void debug(Object...os) {
		System.out.println(Arrays.deepToString(os));
	}
	//--------------------- IO stuffs ---------------------
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new Main());
        thread.start();
        thread.join();
    }
	public void run() {
        try {
        	reader = _ReadFromFile ? new BufferedReader(new FileReader(IN_FILE)) : new BufferedReader(new InputStreamReader(System.in));
        	writer = _WriteToFile ? new PrintWriter(OUT_FILE) : new PrintWriter(new BufferedOutputStream(System.out));
            tokenizer = null;
            core();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
    int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }
    long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }
    double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
    String nextToken() throws Exception {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}
