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.*;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.util.Collections;
    import java.io.InputStreamReader;
    import static java.lang.Math.*;
    import static java.lang.System.*;

    public class Main1 {
    static  int n ;
    static int a[] , b[] ;
    static  long dp[][] ;


    static long solver(int N , int t){
      if (t >=n)return 0 ;
        if (n == N)return Long.MAX_VALUE/100;
     //   if (t < 0)return Long.MAX_VALUE/2 ;

        if (dp[N][t] != -1)return dp[N][t] ;
        long ans = Long.MAX_VALUE/100 ;

            ans = min(ans , solver(N+1 , t)) ;
        ans = min(ans  , b[N] + solver(N+1 , t+a[N]+1)) ;

        return dp[N][t] = ans ;
    }



        public static void main(String[] args) throws IOException {

    //       try {
           // Scanner in = new Scanner(System.in) ;
             FastScanner in = new FastScanner();
           PrintWriter out = new PrintWriter(System.out);


            n = in.nextInt() ;
              a = new int[n] ;
              b = new int[n] ;

            for (int i = 0; i <n ; i++) {
                a[i] = in.nextInt() ;
                b[i] = in.nextInt() ;
            }
            dp = new long[2000][2000] ;

            for (int i = 0; i <2000 ; i++) {
                for (int j = 0; j <2000 ; j++) {
                    dp[i][j] = -1 ;
                }
            }

            long ans = solver(0 , 0 ) ;
            System.out.println(ans);



            out.flush();
            out.close();

        }
    //        catch (Exception e){
    //            return;
    //        }
    //
    //    }

        static long gcd(long a, long b) {
            return (b == 0) ? a : gcd(b, a % b);
        }

        static int gcd(int a, int b) {
            return (b == 0) ? a : gcd(b, a % b);
        }

        static void sort(int ar[]) {
            int n = ar.length;
            ArrayList<Integer> a = new ArrayList<>();
            for (int i = 0; i < n; i++)
                a.add(ar[i]);
            Collections.sort(a);
            for (int i = 0; i < n; i++)
                ar[i] = a.get(i);
        }

        static void sort1(long ar[]) {
            int n = ar.length;
            ArrayList<Long> a = new ArrayList<>();
            for (int i = 0; i < n; i++)
                a.add(ar[i]);
            Collections.sort(a);
            for (int i = 0; i < n; i++)
                ar[i] = a.get(i);
        }

        static long ncr(long n, long r, long mod) {
            if (r == 0)
                return 1;
            long val = ncr(n - 1, r - 1, mod);
            val = (n * val) % mod;
            val = (val * modInverse(r, mod)) % mod;
            return val;
        }

        static long fast_pow(long base, long n, long M) {
            if (n == 0)
                return 1;
            if (n == 1)
                return base % M;
            long halfn = fast_pow(base, n / 2, M);
            if (n % 2 == 0)
                return (halfn * halfn) % M;
            else
                return (((halfn * halfn) % M) * base) % M;
        }

        static long modInverse(long n, long M) {
            return fast_pow(n, M - 2, M);
        }

    // ======================================================================================================



        static class FastOutput implements AutoCloseable, Closeable, Appendable {
            private static final int THRESHOLD = 32 << 10;
            private final Writer os;
            private StringBuilder cache = new StringBuilder(THRESHOLD * 2);

            public FastOutput append(CharSequence csq) {
                cache.append(csq);
                return this;
            }

            public FastOutput append(CharSequence csq, int start, int end) {
                cache.append(csq, start, end);
                return this;
            }

            private void afterWrite() {
                if (cache.length() < THRESHOLD) {
                    return;
                }
                flush();
            }

            public FastOutput(Writer os) {
                this.os = os;
            }

            public FastOutput(OutputStream os) {
                this(new OutputStreamWriter(os));
            }

            public FastOutput append(char c) {
                cache.append(c);
                afterWrite();
                return this;
            }

            public FastOutput append(long c) {
                cache.append(c);
                afterWrite();
                return this;
            }

            public FastOutput append(String c) {
                cache.append(c);
                afterWrite();
                return this;
            }

            public FastOutput println() {
                return append(System.lineSeparator());
            }

            public FastOutput flush() {
                try {
                    //            boolean success = false;
                    //            if (stringBuilderValueField != null) {
                    //                try {
                    //                    char[] value = (char[]) stringBuilderValueField.get(cache);
                    //                    os.write(value, 0, cache.length());
                    //                    success = true;
                    //                } catch (Exception e) {
                    //                }
                    //            }
                    //            if (!success) {
                    os.append(cache);
                    //            }
                    os.flush();
                    cache.setLength(0);
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
                return this;
            }

            public void close() {
                flush();
                try {
                    os.close();
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }

            public String toString() {
                return cache.toString();
            }

        }


        static class FastScanner {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            StringTokenizer st = new StringTokenizer("");

            String next() {
                while (!st.hasMoreTokens())
                    try {
                        st = new StringTokenizer(br.readLine());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                return st.nextToken();
            }

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

            int[] readArray(int n) {
                int[] a = new int[n];
                for (int i = 0; i < n; i++) a[i] = nextInt();
                return a;
            }


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


    }







