#include <bits/stdc++.h>
using namespace std;
int n, m = 1000, a[1000], dp[1000010];
inline int max(int a, int b) { return a > b ? a : b; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int T = 1; T < n; T++) {
    for (int i = 0; i <= m; i++) dp[i] = 0;
    for (int i = a[T]; i <= m; i++)
      dp[i] = max(dp[i], dp[i - a[T]] + a[T + 1] - a[T]);
    m += dp[m];
  }
  printf("%d\n", m);
  return 0;
}
