#include <bits/stdc++.h>
using namespace std;
int f[20000001], a[10001];
int t, n, m;
int ans;
int main() {
  cin >> t;
  ans = 1000;
  for (int i = 1; i <= t; i++) cin >> a[i];
  for (int i = 1; i < t; i++) {
    for (int j = 1; j <= ans; j++) f[j] = -99999999;
    f[ans] = ans;
    for (int k = ans; k >= a[i]; k--)
      f[k - a[i]] = max(f[k - a[i]], f[k] + a[i + 1] - a[i]);
    int sum = 0;
    for (int j = 0; j <= ans; j++) sum = max(sum, f[j]);
    ans = max(ans, sum);
  }
  cout << ans;
  return 0;
}
