#include <bits/stdc++.h>
int t, n, m, p[110][110], dp[1010 * 110], ans;
inline int max(int a, int b) { return a > b ? a : b; }
int main() {
  scanf("%d", &t);
  n = 1, m = 1000;
  for (int i = 1; i <= t; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &p[i][j]);
  for (int T = 1; T < t; T++) {
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++)
      for (int j = p[T][i]; j <= m; j++)
        dp[j] = max(dp[j], dp[j - p[T][i]] + p[T + 1][i] - p[T][i]);
    m += dp[m];
  }
  printf("%d\n", m);
  return 0;
}
