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.util.*;
import java.io.*;

public class Solution
{
       static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;
 
        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
 
        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(
                new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
 
        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n') {
                    if (cnt != 0) {
                        break;
                    }
                    else {
                        continue;
                    }
                }
                buf[cnt++] = (byte)c;
            }
            return new String(buf, 0, cnt);
        }
 
        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ') {
                c = read();
            }
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
 
            if (neg)
                return -ret;
            return ret;
        }
 
        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }
 
        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
 
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
 
            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }
 
            if (neg)
                return -ret;
            return ret;
        }
 
        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0,
                                 BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }
 
        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
 
        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
    static int parent(int x , int p[])
    {
           if(p[x] == x)
           return x;
           
           return (p[x] = parent(p[x],p));
    }
    
    static void union(int a , int b , int p[] , int size[])
    {
           a = parent(a,p);
           b = parent(b,p);
           
           if(size[a] < size[b])
           {
                  int temp = a;
                  a = b;
                  b = temp;
           }
           p[b] = a;
           size[a] += size[b];
    }
    
   
  
  static int max(int x)
  {
         for(int j = 30 ; j >= 0 ; j--)
         {
                if((x&(1<<j)) > 0)
                return j;
         }
         return -1;
  }
  static void dfs(int n , LinkedList<Integer> arr[] , int p , int pp[])
  {
         pp[n] = p;
         for(Integer i : arr[n])
         {
                if(i != p)
                {
                       dfs(i,arr,n,pp);
                }
         }
  }
  
  static void dfs2(int n , LinkedList<Integer> arr[] , int p , int w[] , long dp[] , long max[])
  {
         long mx = 0;
         for(Integer i : arr[n])
         {
                if(i != p)
                {
                       dfs2(i,arr,n,w,dp,max);
                       dp[n] += dp[i]+2*w[i];
                       mx = Math.max(mx,w[i]+max[i]);   
                }
         }
         max[n] = mx;
  }
  
 static int getSum( int index , int BITree[])
{
    int sum = 0; // Iniialize result
  
    // index in BITree[] is 1 more than the index in arr[]
   // index = index + 1;
  
    // Traverse ancestors of BITree[index]
    while (index>0)
    {
        // Add current element of BITree to sum
        sum += BITree[index];
  
        // Move index to parent node in getSum View
        index -= index & (-index);
    }
    return sum;
}
  
// Updates a node in Binary Index Tree (BITree) at given index
// in BITree. The given value 'val' is added to BITree[i] and 
// all of its ancestors in tree.
static void updateBIT(int n, int index, int val , int BITree[])
{
    // index in BITree[] is 1 more than the index in arr[]
    //index = index + 1;
  
    // Traverse all ancestors and add 'val'
    while (index <= n)
    {
    // Add 'val' to current node of BI Tree
    BITree[index] += val;
  
    // Update index to that of parent in update View
    index += index & (-index);
    }
}
static int max;
static long inv(int arr[])
{
       int n = arr.length;
       int bit[]  = new int[n+1];
       long ans = 0;
       for(int i = 0 ; i < n; i++)
       {
              updateBIT(n,arr[i],1,bit);
              ans += getSum(n,bit)-getSum(arr[i],bit);
       }
       return ans;
}


static void dfs(int n , int arr[] , LinkedList<Integer> g[] , HashMap<Integer,Integer> map[] , int prime[] , int p)
{
      HashMap<Integer,Integer> mx = new HashMap<Integer,Integer>(); 
       HashMap<Integer,Integer> nextmx = new HashMap<Integer,Integer>(); 
       
       int temp = arr[n];
       for(Integer i : g[n])
       {
              if(i != p)
              {
                     dfs(i,arr,g,map,prime,n);
                     for(Map.Entry entry : map[i].entrySet())
                     {
                            int k = (int)entry.getKey();
                            int v = (int)entry.getValue();
                            
                            if(arr[n]%k == 0)
                            {
                            if(!mx.containsKey(k))
                            mx.put(k,v);
                            
                            else if(!nextmx.containsKey(k))
                            {
                                 if(v >= mx.get(k))
                                 {
                                         nextmx.put(k,mx.get(k));
                                          mx.put(k,v);
                                 }
                                 
                                 else
                                 {
                                        nextmx.put(k,v);
                                 }
                            }
                            
                            
                            else
                            {
                                   if(v >= mx.get(k))
                                   {
                                          nextmx.put(k,mx.get(k));
                                          mx.put(k,v);
                                   }
                                   
                                   else if(v >= nextmx.get(k))
                                   nextmx.put(k,v);
                            }
                     }
              }
       }
}

while(temp > 1)
{
       int x = prime[temp];
       while(temp%x == 0)
       {
              temp = temp/x;
       }
      // int curr = 0;
       if(mx.containsKey(x))
       {
              max = Math.max(max,mx.get(x)+1);
              
              if(nextmx.containsKey(x))
              max = Math.max(max,mx.get(x)+nextmx.get(x)+1);
              
              map[n].put(x,mx.get(x)+1);
       }
       
       else
       {
       map[n].put(x,1);
       max = Math.max(max,1);
       }
}

}
static long dp[][];
static long knapsack(int pos , int left , int t[] , int c[])
{
       if(left <= 0)
       return 0;
       
       if(pos == c.length)
       return 1000000000000000L;
       
       if(dp[pos][left] != -1)
       return dp[pos][left];
       
       dp[pos][left] = Math.min(c[pos]+knapsack(pos+1,left-t[pos],t,c),
                         knapsack(pos+1,left,t,c));
                         
                         return dp[pos][left];
}
       public static void main(String []args) throws IOException
       {
              Reader sc = new Reader();
              int n = sc.nextInt();
              int t[] = new int[n];
              int c[] = new int[n];
              long sum = 0;
              for(int i = 0 ; i< n ; i++)
              {
                     t[i] = sc.nextInt();
                     t[i]++;
                     c[i] = sc.nextInt();
                     sum += c[i];
              }
              dp = new long[n][n+1];
              for(int i = 0 ; i< n ; i++)
              {
                     for(int j = 0 ; j <= n ; j++)
                     {
                            dp[i][j] = -1;
                     }
              }
              System.out.println(knapsack(0,n,t,c));
       }
}