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 static java.lang.Math.*;

import java.lang.reflect.Array;
import java.util.*;
import java.util.function.*;
import java.lang.*;

public class Main {
    final static boolean debug = false;
    final static String fileName = "";
    final static boolean useFiles = false;

    public static void main(String[] args) throws FileNotFoundException {
        long start;
        if (debug)
            start = System.nanoTime();
        InputStream inputStream;
        OutputStream outputStream;
        if (useFiles) {
            inputStream = new FileInputStream(fileName + ".in");
            outputStream = new FileOutputStream(fileName + ".out");
        } else {
            inputStream = System.in;
            outputStream = System.out;
        }
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task(in, out);
        solver.solve();
        if(debug)
            out.println((System.nanoTime() - start) / 1e+9);
        out.close();
    }
}
class Task {
    public void solve() {
        final long inf = (long) (1e+18);
        int n = in.nextInt();
        int[] price = new int[n];
        int[] count = new int[n];
        for (int i = 0; i < n; i++) {
            count[i] = in.nextInt() + 1;
            price[i] = in.nextInt();
        }
        long[][] d = new long[n][n];
        for (int i = 0; i < n; i++)
            for (int sum = 1; sum < n; sum++)
                d[i][sum] = inf;

        long[] over = new long[n];
        Arrays.fill(over, inf);
        if (count[0] >= n)
            over[0] = price[0];

        if (count[0] < n)
            d[0][count[0]] = price[0];
        for (int i = 1; i < n; i++) {
            for (int sum = 1; sum < n; sum++) {
                d[i][sum] = d[i - 1][sum];
                if (sum - count[i] >= 0)
                    d[i][sum] = min(d[i][sum], d[i - 1][sum - count[i]] + price[i]);
            }
            over[i] = over[i - 1];
            for (int sum = max(n - count[i], 0); sum < n; sum++){
                over[i] = min(over[i], d[i - 1][sum] + price[i]);
            }
        }
        out.println(over[n - 1]);
    }

    private InputReader in;
    private PrintWriter out;

    Task(InputReader in, PrintWriter out) {
        this.in = in;
        this.out = out;
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public double nextDouble(){
        return Double.parseDouble(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong(){
        return Long.parseLong(next());
    }

    public byte nextByte(){
        return Byte.parseByte(next());
    }
}