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
#include <bits/stdc++.h>
using namespace std;
bool compare(const pair<int, double> &i, const pair<int, double> &j) {
  return i.second < j.second;
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void FastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void txtINPUT() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
bool comparator(const pair<string, int> &p1, const pair<string, int> &p2) {
  if (p1.second != p2.second)
    return p1.second > p2.second;
  else
    return p1.first < p2.first;
}
int countbits(int n) {
  int cnt = 0;
  while (n) {
    if (n & 1) cnt++;
    n = n >> 1;
  }
  return cnt;
}
long long fastPower(int x, int y) {
  if (y == 1) return x;
  if (y == 0) return 1;
  if (y % 2) return x * fastPower(x, y - 1);
  long long ans = fastPower(x, y / 2);
  return ans * ans;
}
bool vis[550];
vector<vector<pair<int, int>>> adj;
int x[] = {0, 0, -1, 1, -1, -1, 1, 1, 0};
int y[] = {1, -1, 0, 0, 1, -1, 1, -1, 0};
bool valid(int r, int c) { return r >= 0 && r < 8 && c >= 0 && c < 8; }
vector<string> nodes;
vector<pair<int, pair<int, int>>> edges;
struct DSU {
  vector<int> parent;
  vector<int> size;
  void init(int n) {
    parent.resize(n);
    size.resize(n);
    for (int i = 0; i < n; i++) {
      parent[i] = i;
      size[i] = 1;
    }
  }
  int root(int node) {
    if (parent[node] == node) return node;
    return parent[node] = root(parent[node]);
  }
  bool isUnion(int node1, int node2) {
    int p1 = root(node1);
    int p2 = root(node2);
    if (p1 == p2) return true;
    return false;
  }
  int getSize(int node) {
    int par = root(node);
    return size[par];
  }
  void link(int node1, int node2) {
    int p1 = root(node1);
    int p2 = root(node2);
    if (size[p1] > size[p2]) swap(p1, p2);
    parent[p1] = p2;
    size[p2] += size[p1];
  }
};
int n;
const long long OO = 1e15;
const double EPS = (1e-7);
const int maxN = 2000 + 9;
long long memo[maxN][maxN];
long long cost[maxN], time_[maxN];
long long solve(long long indx, long long curtime) {
  if (curtime >= n) return 0;
  if (indx == n) return OO;
  long long &ret = memo[indx][curtime];
  if (ret != -1) return ret;
  long long steal = solve(indx + 1, curtime);
  long long pay = cost[indx] + solve(indx + 1, curtime + time_[indx] + 1);
  return ret = min(pay, steal);
}
int main() {
  FastIO();
  cin >> n;
  memset(memo, -1, sizeof(memo));
  for (int i = 0; i < n; i++) cin >> time_[i] >> cost[i];
  cout << solve(0, 0) << "\n";
  return 0;
}
