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.Arrays;

public class B {
    static class Parser {
        final private int BUFFER_SIZE = 1 << 16;

        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Parser(InputStream in) {
            din = new DataInputStream(in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public char nextChar() throws Exception {
            byte c = read();
            while (c <= ' ')
                c = read();
            return (char) c;
        }

        public int nextLong() throws Exception {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = c == '-';
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
                c = read();
            } while (c > ' ');
            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws Exception {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws Exception {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
    }

    static class struct1 implements Comparable<struct1> {
        int val, t;

        public struct1(int tt, int v) {
            val = v;
             t=tt;
        }

        public int compareTo(struct1 x) {
            if (x.val < val)
                return 1;
            return -1;
        }
    }

    static struct1[] itemsCost;
    static long[][] dp;

    public static long solve(int idx, int rem) {
        if (rem <= 0)
            return 0;
        if (idx >= dp.length)
            return 20000000000000L;
        if(dp[idx][rem]!=-1) return dp[idx][rem];
        return dp[idx][rem] = Math.min(solve(idx + 1, rem), itemsCost[idx].val
                + solve(idx + 1, rem - itemsCost[idx].t-1));
    }

    public static void main(String[] args) throws Exception {
        Parser aa = new Parser(System.in);
        int n = aa.nextLong();
        itemsCost = new struct1[n];
        for (int i = 0; i < n; i++) {
            itemsCost[i] = new struct1(aa.nextLong(), aa.nextLong());
            //System.out.println(itemsCost[i].t);
        }
        dp = new long[n][n + 1];
        for (int i = 0; i < n; i++)
            Arrays.fill(dp[i], -1);
        System.out.println(solve(0, n));
    }
}
