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

/**
 * Created by IntelliJ IDEA.
 * User: aircube
 * Date: 11.01.11
 * Time: 4:14
 * To change this template use File | Settings | File Templates.
 */

import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class Template {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;

    public static void main(String[] args) throws IOException {
        new Template().run();
    }

    void run() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        st = null;
        out = new PrintWriter(System.out);
        solve();
        br.close();
        out.close();
    }

    void solve() throws  IOException {
        int n = nextInt();
        int time[] = new int[n];
        int cost[] = new int[n];
        long res = Long.MAX_VALUE / 2;
        for(int i = 0; i < n; ++i) {
            time[i] = nextInt();
            cost[i] = nextInt();
        }
        long dm[] = new long[n + 1];
        Arrays.fill(dm, -1);
        int count[] = new int[n + 1];
        int ddt[] = new int[n + 1];
        int prev [] = new int[n + 1];
        int done [] = new int[n + 1];
        dm[0] = 0;
        count[0] = 0;
        for(int i = 0; i < n; ++i) {
            for(int j = n ; j >= 0; --j) {
                if (dm[j] != -1 && time[i] > 0) {
                    int pid = j + time[i];
                    if (pid > n) continue ;
                    if (dm[pid] == -1 || dm[pid] > dm[j] + cost[i] || dm[pid] == dm[j] + cost[i] && count[pid] < count[j] + 1) {
                        dm[pid] = dm[j] + cost[i];
                        count[pid] = count[j] + 1;
                        prev[pid] = j ;
                        done[pid] = i;
                        ddt[pid] = time[i];
                    }
                }
            }
        }

        for(int t = 0; t <= n; ++t) {
            if (dm[t] != -1) {
                LinkedList<Integer> buy = new LinkedList<Integer>();
                boolean used[] = new boolean[n];
                int c = t;
                int ccc = 0 ;
                while (c != 0) {
                    long dM = dm[c] - dm[prev[c]];
                    int dT = c - prev[c];
                    for(int j = 0; j < n; ++j) {
                        if (!used[j] && dM == cost[j] && dT == time[j]) {
                            used[j] = true;
                            buy.add(j);
                            break;
                        }
                    }
                    c = prev[c];
                    ++ ccc ;
                }
                LinkedList<Pair> list = new LinkedList<Pair> ();
                for(int j = 0; j < used.length; ++j) {
                    if (!used[j]) {
                        list.add(new Pair(j, cost[j]));
                    }
                }

                Collections.sort(list);
                int z = n - t - ccc;
                long cur = dm[t];
                for(int i = 0, j = z; i < list.size() && j > 0; ++i, j --) {
                    cur += cost[list.get(i).id];
                    buy.add(list.get(i).id);
                }
                /*int tt = 0;
                long ss = 0;
                for(int x : buy) {
                    ss += cost[x];
                    tt += time[x];
                }
                if (tt + buy.size() >= n) {
                    res = Math.min(res, ss);
                } */
                res = Math.min(res, cur);
            }
        }
        out.print(res);

    }
    class Tuple implements  Comparable<Tuple> {
        int dM , dT, id ;

        public int compareTo(Tuple tuple) {
            if (dM != tuple.dM) return dM - tuple.dM;
            if (dT != tuple.dT) return dT - tuple.dT;
            return id - tuple.id;
        }

        Tuple(int dM, int dT, int id) {
            this.dM = dM;
            this.dT = dT;
            this.id = id;
        }
    }
    class Pair implements Comparable<Pair>{
        int id, val ;

        Pair(int id, int val) {
            this.id = id;
            this.val = val;
        }

        public int compareTo(Pair pair) {
            if (val != pair.val) return val - pair.val;
            return id - pair.id;
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}