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.awt.geom.Point2D;
import java.text.*;
import java.math.*;
import java.util.*;

public class Main implements Runnable {
	
	final String filename="";
	
	public void solve() throws Exception {
		final long inf = 1000000000000000L;
//		final int max = 2001;
		final int max = 40;
		int n = iread();
		int[] t = new int[n], s = new int[n];
		for (int i=0; i<n; i++)
		{
			t[i] = iread();
			s[i] = iread();
			t[i]++;
		}
		long[] a = new long[n+1];
		Arrays.fill(a, inf);
		a[0] = 0;
		for (int i=0; i<=n-1; i++)
		{
			for (int j=n; j>=0; j--)
			{
				int jj = Math.max(0, j-t[i]);
				a[j] = Math.min(a[j], a[jj]+s[i]);
				if (j<n)
					a[j] = Math.min(a[j+1], a[j]);
			}
		}
		long ans = a[n];
		out.write(ans+"\n");
	}
	
	class team implements Comparable<team>
	{
		String name;
		int score, goals, lost;
		public team(String name)
		{
			this.name = name;
		}
		@Override
		public int compareTo(team o) {
			if (score!=o.score)
				return score-o.score;
			if (goals-lost!=o.goals-o.lost)
				return (goals-lost) - (o.goals-o.lost);
			return goals-o.goals;
		}
	}
	
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new BufferedWriter(new OutputStreamWriter(System.out));
//			in = new BufferedReader(new FileReader(filename+".in"));
//			out = new BufferedWriter(new FileWriter(filename+".out"));
			solve();
			out.flush();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
	
	public int iread() throws Exception {
		return Integer.parseInt(readword());
	}

	public double dread() throws Exception {
		return Double.parseDouble(readword());
	}

	public long lread() throws Exception {
		return Long.parseLong(readword());
	}

	BufferedReader in;

	BufferedWriter out;

	public String readword() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}
	public static void main(String[] args) {
		try{
			Locale.setDefault(Locale.US);
		} catch (Exception e)
		{
			
		}
		new Thread(new Main()).start();
		//new Thread(null, new Main(), "1", 1<<25).start();
	}
}