#include <bits/stdc++.h>
using namespace std;
int max_profit(int a[], int b[], int n, int fee) {
  int i, j, profit;
  int l, r, diff_day = 1, sum = 0;
  b[0] = 0;
  b[1] = diff_day;
  for (i = 1; i < n; i++) {
    l = 0;
    r = diff_day;
    sum = 0;
    for (j = n - 1; j >= i; j--) {
      profit = (a[r] - a[l]) - fee;
      if (profit > 0) {
        sum = sum + profit;
      }
      l++;
      r++;
    }
    if (b[0] < sum) {
      b[0] = sum;
      b[1] = diff_day;
    }
    diff_day++;
  }
  return 0;
}
int main() {
  int n, i, j, k, m, q;
  cin >> n;
  int ar[n];
  for (i = 0; i < n; i++) cin >> ar[i];
  int b[2];
  int tranFee = 0;
  max_profit(ar, b, n, tranFee);
  cout << b[0] << endl;
  return 0;
}
