#include <bits/stdc++.h>
using namespace std;
int t, n, m, p[9000][20];
int dp[100010];
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 i = 2; i <= t; i++) {
    memset(dp, 0, sizeof(dp));
    for (int j = 1; j <= n; j++)
      for (int k = p[i - 1][j]; k <= m; k++)
        if (dp[k] < dp[k - p[i - 1][j]] + p[i][j] - p[i - 1][j])
          dp[k] = dp[k - p[i - 1][j]] + p[i][j] - p[i - 1][j];
    m += dp[m];
  }
  printf("%d", m);
}
