#include <bits/stdc++.h>
using namespace std;
const int MAXN = 85;
int f[1000005], a[MAXN][MAXN];
int t, n, m, ans;
int main() {
  scanf("%d", &t);
  m = 1000, n = 1;
  for (int i = 1; i <= t; ++i) {
    for (int j = 1; j <= n; ++j) {
      scanf("%d", &a[i][j]);
    }
  }
  ans = m;
  for (int i = 1; i < t; ++i) {
    memset(f, ~0x3f, sizeof(f));
    f[ans] = ans;
    for (int j = 1; j <= n; ++j) {
      for (int k = ans; k >= a[i][j]; --k) {
        f[k - a[i][j]] = max(f[k - a[i][j]], f[k] + a[i + 1][j] - a[i][j]);
      }
    }
    int mx = 0;
    for (int j = 0; j <= ans; ++j) mx = max(mx, f[j]);
    ans = mx;
  }
  cout << ans << endl;
  return 0;
}
