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 FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
    static final long mod=(long)1e9+7;
    public static long pow(long a,int p)
    {
        long res=1;
        while(p>0)
        {
            if(p%2==1)
            {
                p--;
                res*=a;
                res%=mod;
            }
            else
            {
                a*=a;
                a%=mod;
                p/=2;
            }
        }
        return res;
    }
    // static class Pair
    // {
    //     int u,v;
    //     Pair(int u,int v)
    //     {
    //         this.u=u;
    //         this.v=v;
    //     }
    // }
    static class Pair implements Comparable<Pair>
    {
        int u;
        long v;
        Pair(int uu,long vv)
        {
            this.u=uu;
            this.v=vv;
        }
        public int compareTo(Pair p)
        {
            if(p.u!=u)
            return p.u-u;
            if(p.v<v)
            return 1;
            return -1;
        }
    }
    static long gcd(long a,long b)
    {
        if(b%a==0)
        return a;
        return gcd(b%a,a);
    }
    // public static class comp implements Comparator<Pair>
    // {
    //     public int compare(Pair p1,Pair p2)
    //     {
    //         if(p1.v>p2.v)
    //         return 1;
    //         return -1;
    //     }
    // }
    public static void dfs(int u,int dist[],ArrayList<Integer> edge[],boolean vis[])
    {
        vis[u]=true;
        for(int v:edge[u])
        {
            if(!vis[v])
            {
                dist[v]=dist[u]+1;
                dfs(v,dist,edge,vis);
            }
        }
    }
    public static void main(String args[])throws Exception
    {
        FastReader fs=new FastReader();
        PrintWriter pw=new PrintWriter(System.out);
        // int tc=fs.nextInt();
        int n=fs.nextInt();
        Pair p[]=new Pair[n];
        long ans=0;
        for(int i=0;i<n;i++)
        {
            p[i]=new Pair(fs.nextInt(),fs.nextLong());
            ans+=p[i].v;
        }
        Arrays.sort(p);
        int cnt[]=new int[4005];
        long t[]=new long[4005];
        int come[]=new int[4005];
        Arrays.fill(t,Long.MAX_VALUE);
        t[0]=0;
        for(int i=0;i<n;i++)
        {
            come[i]=i;
            for(int j=2000;j>=0;j--)
            {
                if(t[j]!=Long.MAX_VALUE&&(t[j]+p[i].v)<=t[j+p[i].u])
                {
                    t[j+p[i].u]=t[j]+p[i].v;
                    cnt[j+p[i].u]=cnt[j]+1;
                    come[j+p[i].u]=i;
                }
            }
        }
        for(int i=1;i<=2000;i++)
        {
            if(t[i]!=Long.MAX_VALUE)
            {
                long s=t[i];
                int tt=i;
                boolean vis[]=new boolean[n];
                while(come[tt]!=tt)
                {
                    //System.out.println(tt);
                    vis[come[tt]]=true;
                    tt=come[tt];
                }
                ArrayList<Long> list=new ArrayList<>();
                for(int j=0;j<n;j++)
                {
                    if(!vis[j])
                    list.add(p[j].v);
                }
                Collections.sort(list);
                int req=n-(i+cnt[i]);
                for(int j=0;j<req;j++)
                s+=list.get(j);
                ans=Math.min(ans,s);
            }
        }
        pw.println(ans);
        pw.flush();
        pw.close();
    }
}