#include <climits>
#include <cmath>
#include <iostream>

const int MAX_N = 200000;

int main() {
  int n = 0;
  int prices[MAX_N] = {0};

  int maxProfit = INT_MIN;

  std::cin >> n;

  for (int i = 0; i < n; i++) {
    std::cin >> prices[i];

    for (int j = i - 1; j >= 0; j--) {
      maxProfit = std::max(maxProfit, prices[i] - prices[j]);
    }
  }

  std::cout << maxProfit << std::endl;

  return 0;
}

#include <climits>
#include <cmath>
#include <iostream>

const int MAX_N = 200000;

int main() {
  int n = 0;
  int prices[MAX_N] = {0};

  std::cin >> n;

  for (int i = 0; i < n; i++) {
    std::cin >> prices[i];
  }

  int minv = prices[0];
  int maxv = INT_MIN;

  for (int i = 1; i < n; i++) {
    maxv = std::max(maxv, prices[i] - minv);
    minv = std::min(minv, prices[i]);
  }

  std::cout << maxv << std::endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(void) {
  int n;
  cin >> n;
  vector<int> r(n);
  for (int i = 0; i < n; ++i) {
    cin >> r[i];
  }
  int ans = -1000000007;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      ans = max(ans, r[j] - r[i]);
    }
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main(void) {
  int n;
  cin >> n;
  vector<int> r(n);
  for (int i = 0; i < n; ++i) {
    cin >> r[i];
  }
  int ans = -1000000007;
  int minv = r[0];
  for (int i = 1; i < n; ++i) {
    ans = max(ans, r[i] - minv);
    minv = min(minv, r[i]);
  }
  cout << ans << endl;
  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;

static const int MAX = 200000;

int main() {
  int R[MAX]; //???????????????
  int n;      //????????°

  //??\\???
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> R[i];
  }

  //?¨????
  int maxv = -2000000000; //???????°??????????????????????????¨????
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  //??????
  cout << maxv << endl;

  return 0;
}

int max(int oldMax, int newMax) {
  int nowMax;

  nowMax = oldMax;
  if (newMax > oldMax) {
    nowMax = newMax;
  }

  return nowMax;
}

int min(int oldMin, int newMin) {
  int nowMin;

  nowMin = oldMin;
  if (newMin > oldMin) {
    nowMin = newMin;
  }

  return nowMin;
}


#include <climits>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> data(n);
  int max = INT_MIN;
  for (auto &a : data) {
    cin >> a;
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (data[j] - data[i] > max)
        max = data[j] - data[i];
    }
  }
  cout << max << endl;
}

#include <climits>
#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int data;
  int MAX = INT_MIN;
  int MIN = INT_MAX;
  for (int i = 0; i < n; i++) {
    cin >> data;
    MAX = max(MAX, data - MIN);
    MIN = min(MIN, data);
  }
  cout << MAX << endl;
}


#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main(void) {
  int n;
  cin >> n;

  vector<int> prices(n);
  for (int i = 0; i < n; i++) {
    cin >> prices[i];
  }

  int mprofit = -1000000000;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      mprofit = max(mprofit, prices[j] - prices[i]);
    }
  }

  cout << mprofit << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main(void) {
  int n;
  cin >> n;

  vector<int> prices(n);
  for (int i = 0; i < n; i++) {
    cin >> prices[i];
  }

  int mprofit = -1111111111;
  int minv = prices[0];
  for (int i = 1; i < n; i++) {
    mprofit = max(mprofit, prices[i] - minv);
    minv = min(minv, prices[i]);
  }

  cout << mprofit << endl;
  return 0;
}


#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const int inf = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  int a[n];
  int ans = -inf;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j <= n - 1; j++) {
      if (a[j] - a[i] > ans) {
        ans = a[j] - a[i];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const int inf = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  int min = INT_MAX;
  int max = -INT_MAX;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    if (max < tmp - min) {
      max = tmp - min;
    }
    if (min > tmp) {
      min = tmp;
    }
  }
  cout << max << endl;
  return 0;
}


#include <stdio.h>

int main(void) {
  int n;
  int ans;
  scanf("%d", &n);
  int r[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &r[i]);
  }
  ans = r[1] - r[0];
  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j > i; j--) {
      if (ans < r[j] - r[i]) {
        ans = r[j] - r[i];
      }
    }
  }
  printf("%d\\n", ans);
  return 0;
}

#include <stdio.h>

int main(void) {
  int n;
  long ans, min;
  scanf("%d", &n);
  long r[n];
  for (int i = 0; i < n; i++) {
    scanf("%ld", &r[i]);
  }
  ans = r[1] - r[0];
  min = r[0];
  for (int i = 1; i < n; i++) {
    if (min > r[i]) {
      min = r[i];
    } else {
      long temp = r[i] - min;
      if (ans < temp) {
        ans = temp;
      }
    }
  }
  printf("%ld\\n", ans);
  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n, result = 0, f_result = 0;

  cin >> n;

  int num[n];

  for (int i = 0; i < n; i++) {
    cin >> num[i];
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      result = num[j] - num[i];
      if (i == 0 && j == 1) {
        f_result = result;
      } else if (result > f_result) {
        f_result = result;
      }
    }
  }

  cout << f_result << "\\n";

  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int n, result, m;

  cin >> n;

  int num[n];

  for (int i = 0; i < n; i++) {
    cin >> num[i];
  }
  m = num[0];
  result = num[1] - num[0];

  for (int i = 1; i < n; i++) {
    result = max(result, num[i] - m);
    m = min(m, num[i]);
  }

  cout << result << "\\n";

  return 0;
}


#include <stdio.h>

int main(void) {
  int r[200000], n, min, max, i;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", r[i]);
  }

  for (i = 0; i < n; i++) {
    if (i > 0) {
      if (r[i] > max) {
        max = r[i];
      } else if (r[i] < min) {
        min = r[i];
      }
    } else {
      max = r[i];
      min = r[i];
    }
  }

  printf("%d\\n", max - min);

  return 0;
}


#include <iostream>
static const int MAX = 200000;
using namespace std;

int main() {
  int max, n, num_list[MAX];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num_list[i];
  }
  max = num_list[1] - num_list[0];
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      int result = num_list[j] - num_list[i];
      if (max < result) {
        max = result;
      }
    }
  }
  cout << max << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;

int main() {
  int n, num_list[MAX];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> num_list[i];
  int maxv, minv;
  maxv = num_list[1] - num_list[0];
  minv = num_list[0];
  for (int i = 1; i < n; i++) {
    maxv = max(maxv, num_list[i] - minv);
    minv = min(minv, num_list[i]);
  }

  cout << maxv << endl;
  return 0;
}


#include <stdio.h>

#define MAX 200000

int main() {
  long n, i, maxP = -20000000000;
  long a[MAX];
  long x, k;
  scanf("%ld", &n);
  for (i = 0; i < n; i++)
    scanf("%ld", &a[i]);
  for (i = 1; i < n; i++) {
    for (k = 0; k < i; k++) {
      x = a[i] - a[k];
      if (x > maxP)
        maxP = x;
    }
  }
  printf("%ld\\n", maxP);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  int R[n];
  for (int t = 0; t < n; t++) {
    cin >> R[t];
  }
  int maxv = R[1] - R[0];
  int minv = R[0];
  for (int j = 1; j < n; j++) {
    maxv = max(maxv, R[j] - minv);
    minv = min(minv, R[j]);
  }
  printf("%d\\n", maxv);
  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int dataset;
  cin >> dataset;
  int miin[20000];
  int ma = -2047483647;
  int a[20000];
  for (size_t i = 0; i < dataset; i++) {
    cin >> a[i];
  }
  miin[0] = a[0];
  for (size_t i = 1; i < dataset - 1; i++) {
    miin[i] = min(miin[i - 1], a[i]);
  }
  for (size_t i = 1; i < dataset; i++) {
    ma = max(ma, a[i] - miin[i - 1]);
  }
  cout << ma << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int dataset;
  cin >> dataset;
  int miin[200000];
  int ma = -2047483647;
  int a[200000];
  for (size_t i = 0; i < dataset; i++) {
    cin >> a[i];
  }
  miin[0] = a[0];
  for (size_t i = 1; i < dataset - 1; i++) {
    miin[i] = min(miin[i - 1], a[i]);
  }
  for (size_t i = 1; i < dataset; i++) {
    ma = max(ma, a[i] - miin[i - 1]);
  }
  cout << ma << endl;
  return 0;
}


#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#include <stdio.h>
int main() {
  long long int r[200001] = {0}, i, j, n, max = -1000000000, c;
  scanf("%lld", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &r[i]);
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      c = r[j] - r[i];
      if (c > max) {
        max = c;
      }
    }
  }
  printf("%lld\\n", max);
  return 0;
}

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#include <stdio.h>
int main() {
  long long int r[200001] = {0}, i, j, n, max = -1000000000, c, prev;
  prev = 1000000001;
  scanf("%lld", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &r[i]);
  }
  for (i = 0; i < n; i++) {
    if (prev <= r[i])
      continue;
    for (j = i + 1; j < n; j++) {
      c = r[j] - r[i];
      if (c > max) {
        max = c;
      }
    }
    prev = r[i];
  }
  printf("%lld\\n", max);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(asd, fgh) for (int asd = 0; asd < fgh; asd++)

int main(void) {
  int n;
  int r[200000];
  int res = INT_MIN;
  cin >> n;
  REP(i, n) { cin >> r[i]; }

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      res = max(res, r[j] - r[i]);
    }
  }

  cout << res << endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(asd, fgh) for (int asd = 0; asd < fgh; asd++)
#define MAX_N 200000

int main(void) {
  int n;
  int a[MAX_N];
  int m = INT_MAX;
  int ans = INT_MIN;
  cin >> n;
  REP(i, n) { cin >> a[i]; }

  for (int i = 1; i < n; i++) {
    m = min(m, a[i - 1]);
    ans = max(ans, a[i] - m);
  }

  cout << ans << endl;

  return 0;
}


#include <iostream>
using namespace std;

int functione(int num[], int N);

int main() {
  int n;
  cin >> n;
  int *num = new int[n];

  for (int i = 0; i < n; i++)
    cin >> num[i];

  cout << functione(num, n) << endl;
  return 0;
}

int functione(int num[], int N) {
  int profit = -2000000000;
  for (int i = 0; i < N; i++)
    for (int j = i + 1; j < N; j++) {
      if (profit < num[j] - num[i])
        profit = num[j] - num[i];
    }
  return profit;
}

#include <iostream>
using namespace std;

int functione(int num[], int N);

int main() {
  int n;
  cin >> n;
  int *num = new int[n];

  for (int i = 0; i < n; i++)
    cin >> num[i];

  cout << functione(num, n) << endl;
  return 0;
}

int functione(int num[], int N) {
  int max = -2000000000;
  int min = num[0];
  for (int i = 1; i < N; i++) {
    if (max < num[i] - min)
      max = num[i] - min;
    if (min > num[i])
      min = num[i];
  }
  return max;
}


#include <bits/stdc++.h>
using namespace std;
int a[200000];
int main() {
  int n, c = -1000000000, b = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (b < a[j]) {
        b = a[j];
      }
      if (b > a[j]) {
        goto loop;
      }
      if (c < a[j] - a[i]) {
        c = a[j] - a[i];
      }
    loop:;
    }
    b = 0;
  }
  cout << c << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int inf = 2100000000;
int a[200000];
int main() {
  int n, mi = inf, ans = -inf;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] - mi > ans) {
      ans = a[i] - mi;
    }
    if (mi > a[i]) {
      mi = a[i];
    }
  }
  cout << ans << endl;
  return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)

using namespace std;
typedef long long ll;
const int MAXN = 200000;

int R[MAXN], mR[MAXN];

int main() {
  int n;
  int ans = -1e9;

  cin >> n;
  rep(i, n) cin >> R[i];

  for (int i = 0; i < n - 1; i++) {
    int m = 0;
    for (int j = i + 1; j < n; j++) {
      if (R[j] > m)
        m = R[j];
    }
    mR[i] = m;
  }
  rep(i, n - 1) {
    if (mR[i] - R[i] > ans)
      ans = mR[i] - R[i];
  }
  cout << ans << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)

using namespace std;
typedef long long ll;
const int MAXN = 200000;

int R[MAXN];

int main() {
  int n;

  cin >> n;
  rep(i, n) cin >> R[i];

  int maxv = -1e9;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }
  cout << maxv << endl;
  return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int MaximumProfit(vector<int> A, int n) {
  int max = -1000000000;
  for (int i = n - 1; i > 0; i--) {
    for (int j = 1; j <= i; j++) {
      if (max < A[i] - A[i - j])
        max = A[i] - A[i - j];
    }
  }
  return max;
}

int main() {
  int n;
  cin >> n;

  vector<int> A;
  A.resize(n);

  for (int i = 0; i < n; i++)
    cin >> A[i];

  cout << MaximumProfit(A, n) << endl;

  return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int MaximumProfit(vector<int> A, int n) {
  int min = A[0];
  int max = -1000000000;
  for (int i = 1; i < n; i++) {
    max = std::max(max, A[i] - min);
    min = std::min(A[i], min);
  }
  return max;
}

int main() {
  int n;
  cin >> n;

  vector<int> A;
  A.resize(n);

  for (int i = 0; i < n; i++)
    cin >> A[i];

  cout << MaximumProfit(A, n) << endl;

  return 0;
}


#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
using namespace std;

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main() {
  double pai = 3.141592653589;
  int n, r[200000], ans = -1000000001;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &r[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (r[j] - r[i] > ans) {
        ans = r[j] - r[i];
      }
    }
  }
  printf("%d\\n", ans);
  return 0;
}

#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
using namespace std;

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main() {
  double pai = 3.141592653589;
  int n, memo = 1000000001, r[200000], ans = -1000000001;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &r[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    if (memo < r[i]) {
      continue;
    } else {
      memo = r[i];
    }
    for (int j = i + 1; j < n; j++) {
      if (r[j] - r[i] > ans) {
        ans = r[j] - r[i];
      }
    }
  }
  printf("%d\\n", ans);
  return 0;
}


#include <iostream>
#include <stdlib.h>

using namespace std;

int main() {
  int N;
  cin >> N;
  int *A = (int *)malloc(sizeof(int) * (N + 1));
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }

  //??????
  int i, j;
  int v, pro = A[2] - A[1];
  for (i = 1; i < N; i++) {
    for (j = i + 1; j <= N; j++) {
      v = A[j] - A[i];
      if (v > pro) {
        pro = v;
      }
    }
  }
  cout << pro << "\\n";
}

#include <iostream>
#include <math.h>
#include <stdlib.h>

#define INF -99999999999;
using namespace std;

void findcloss(int *A, int low, int high, int mid, int *maxleft, int *maxright,
               int *val) {
  int leftsum = INF;
  int rightsum = INF;
  int sum = 0;

  for (int i = mid; i >= low; i--) {
    sum += A[i];
    if (sum > leftsum) {
      leftsum = sum;
      int *p = &i;
      *maxleft = *p;
    }
  }

  sum = 0;
  for (int i = mid + 1; i <= high; i++) {
    sum += A[i];
    if (sum > rightsum) {
      rightsum = sum;
      int *p = &i;
      *maxright = *p;
    }
  }
  sum = leftsum + rightsum;
  int *p = ∑
  *val = *p;
}

void findmax(int *A, int low, int high, int *anslow, int *anshigh,
             int *ansval) {
  if (high == low) {
    int *p = &low;
    int *q = &high;
    int *r = &A[low];
    *anslow = *p;
    *anshigh = *q;
    *ansval = *r;
  } else {
    int mid = (int)floor((low + high) / 2);
    int leftlow = INF;
    int lefthigh = INF;
    int leftsum = INF;
    findmax(A, low, mid, &leftlow, &lefthigh, &leftsum);
    int rightlow = INF;
    int righthigh = INF;
    int rightsum = INF;
    findmax(A, mid + 1, high, &rightlow, &righthigh, &rightsum);
    int crosslow = INF;
    int crosshigh = INF;
    int crosssum = INF;
    findcloss(A, low, high, mid, &crosslow, &crosshigh, &crosssum);

    if (leftsum >= rightsum && leftsum >= crosssum) {
      int *a = &leftlow;
      int *b = &lefthigh;
      int *c = &leftsum;
      *anslow = *a;
      *anshigh = *b;
      *ansval = *c;
    } else if (rightsum >= leftsum && rightsum >= crosssum) {
      int *a = &rightlow;
      int *b = &righthigh;
      int *c = &rightsum;
      *anslow = *a;
      *anshigh = *b;
      *ansval = *c;
    } else {
      int *a = &crosslow;
      int *b = &crosshigh;
      int *c = &crosssum;
      *anslow = *a;
      *anshigh = *b;
      *ansval = *c;
    }
  }
}
int main() {
  int N;
  cin >> N;
  int *A = (int *)malloc(sizeof(int) * (N + 1));
  int *B = (int *)malloc(sizeof(int) * (N + 1));
  A[0] = 0;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    B[i] = A[i] - A[i - 1];
  }
  // B[i]?????????????????§??¨??????????????????????????°??????.
  int anslow = INF;
  int anshigh = INF;
  int ansval = INF;
  findmax(B, 2, N, &anslow, &anshigh, &ansval);
  cout << ansval << "\\n";

  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int N, max, tmp;
  cin >> N;
  int array[N];
  for (int i = 0; i < N; i++) {
    cin >> array[i];
  }
  max = array[1] - array[0];
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      tmp = array[j] - array[i];
      if (max < tmp) {
        max = tmp;
      }
    }
  }
  cout << max << endl;
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int N, max, min, tmp;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    if (i == 0) {
      min = tmp;
    }
    if (i == 1) {
      max = tmp - min;
    }
    if (max < (tmp - min)) {
      max = tmp - min;
    }
    if (tmp < min) {
      min = tmp;
    }
  }
  cout << max << endl;
  return 0;
}


#include <iostream>

using namespace std;

int main() {
  int R[200000], n;
  int i, max;

  cin >> n;

  for (i = 0; i < n; i++) {
    cin >> R[i];
  }

  max = R[n - 1] - R[0];

  for (int j = n - 1; j > 0; j--) {
    for (i = 0; i <= j - 1; i++) {
      if (max <= R[j] - R[i]) {
        max = R[j] - R[i];
      }
    }
  }

  cout << max << endl;
}

#include <iostream>

using namespace std;

int main() {
  int R[200000], n;
  int i, max, min;

  cin >> n;

  for (i = 0; i < n; i++) {
    cin >> R[i];
  }

  max = R[n - 1] - R[0];

  min = R[0];

  for (int j = 1; j < n; j++) {
    if (max <= R[j] - min) {
      max = R[j] - min;
    }
    if (min >= R[j]) {
      min = R[j];
    }
  }

  cout << max << endl;
}


#include <algorithm>
#include <climits>
#include <cstdio>
using namespace std;
int main() {
  int m = INT_MIN, n;
  scanf("%d", &n);
  int data[n];
  for (int i = 0; i < n; i++)
    scanf("%d", &data[i]);

  for (int i = n - 1; i > 0; i--)
    for (int j = i - 1; j >= 0; j--)
      m = max(m, data[i] - data[j]);

  printf("%d\\n", m);
  return 0;
}

#include <algorithm>
#include <climits>
#include <cstdio>
using namespace std;
int getMaxProfit(int[], int);

int main() {
  int n;
  scanf("%d", &n);
  int data[n];
  for (int i = 0; i < n; i++)
    scanf("%d", &data[i]);

  printf("%d\\n", getMaxProfit(data, n));
  return 0;
}

int getMaxProfit(int data[], int n) {
  int i = 0, key, m = INT_MIN;

  key = data[0];
  for (int i = 1; i < n; i++) {
    if (data[i] - key > m)
      m = data[i] - key;
    if (key > data[i])
      key = data[i];
  }
  return m;
}


#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000000;
int main() {
  int R[MAX], n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }
  cout << maxv << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;
int main() {
  int R[MAX], n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }
  cout << maxv << endl;
  return 0;
}


#include <bits/stdc++.h>
#define LL long long
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  vector<LL> vc(n);

  for (int i = 0; i < n; i++) {
    cin >> vc[i];
  }

  LL res = INT_MIN;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i > j) {
        res = max(res, vc[i] - vc[j]);
      }
    }
  }

  cout << res << endl;

  return 0;
}

#include <bits/stdc++.h>
#define LL long long
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  vector<LL> vc(n);

  for (int i = 0; i < n; i++) {
    cin >> vc[i];
  }

  LL res = INT_MIN;
  LL temp = vc[0];

  for (int i = 1; i < n; i++) {
    res = max(res, vc[i] - temp);
    temp = min(temp, vc[i]);
  }

  cout << res << endl;

  return 0;
}


#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  long R[200000], m = -1000000000;
  int i, j, N;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> R[i];
  }
  for (i = 0; i < N; i++) {
    for (j = i + 1; j < N; j++) {
      if (R[j] - R[i] > m)
        m = R[j] - R[i];
    }
  }
  cout << m << endl;
}

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  long R[200000], m = -1000000000, min;
  int i, j, N;
  cin >> N;
  cin >> min;
  for (j = 0; j < N - 1; j++) {
    cin >> R[j];
    if (R[j] - min > m)
      m = R[j] - min;
    if (min > R[j])
      min = R[j];
  }
  cout << m << endl;
}


#include <iostream>

using namespace std;

class MaximumProfit {
public:
  int solve(int n, int *r);
};

int MaximumProfit::solve(int n, int *r) {
  int maxp = -2000000000;
  for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++) {
      if ((r[j] - r[i]) > maxp)
        maxp = r[j] - r[i];
    }

  return maxp;
}

int main(void) {

  MaximumProfit *mp = new MaximumProfit();

  int n;

  cin >> n;

  int *r = new int[n];

  for (int i = 0; i < n; i++)
    cin >> r[i];

  cout << mp->solve(n, r) << endl;

  delete mp;
  delete[] r;

  return 0;
}

#include <iostream>

using namespace std;

class MaximumProfit {
public:
  int solve(int n, int *r);
};

int MaximumProfit::solve(int n, int *r) {
  int maxp = -2000000000;
  int minr = r[0];
  for (int i = 1; i < n; i++) {
    if ((r[i] - minr) > maxp)
      maxp = r[i] - minr;
    if (r[i] < minr)
      minr = r[i];
  }

  return maxp;
}

int main(void) {

  MaximumProfit *mp = new MaximumProfit();

  int n;

  cin >> n;

  int *r = new int[n];

  for (int i = 0; i < n; i++)
    cin >> r[i];

  cout << mp->solve(n, r) << endl;

  delete mp;
  delete[] r;

  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 20000;
int main() {
  int R[MAX], n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];
  int maxv = -2000000000;
  int minv = R[0];
  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }
  cout << maxv << endl;

  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;
int main() {
  int R[MAX], n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];
  int maxv = -2000000000;
  int minv = R[0];
  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }
  cout << maxv << endl;

  return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
int a[200010];
int main() {
  int n, max = -2000000010, s;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i - 1; j >= 0; j--) {
      s = a[i] - a[j];
      if (s > max)
        max = s;
    }
  }
  printf("%d\\n", max);
  return 0;
}

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a[220000];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int maxa = -9999999999;
  int maxq = a[0];
  for (int i = 1; i < n; i++) {

    maxa = max(maxa, a[i] - maxq);
    maxq = min(maxq, a[i]);
  }
  cout << maxa << endl;
  return 0;
}


//
// Created by yoshihito.hotta on 2018/06/10.
//
#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;

  int *r;
  r = new int[n];

  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }

  int max = -1000000000;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (max < r[j] - r[i]) {
        max = r[j] - r[i];
      }
    }
  }

  cout << max << endl;

  return 0;
}

//
// Created by yoshihito.hotta on 2018/06/10.
//
#include <climits>
#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;

  int *r;
  r = new int[n];

  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }

  int minr;
  int maxv;

  minr = r[0];
  maxv = -INT_MIN;
  for (int i = 1; i < n; i++) {
    if (r[i] - minr > maxv) {
      maxv = r[i] - minr;
    }
    if (r[i] < minr) {
      minr = r[i];
    }
  }

  cout << maxv << endl;

  return 0;
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

int max_profit(vector<int> &price) {
  int a;
  long long int max = -999999999;
  for (int i = 1; i <= price.size() - 1; i++) {
    for (int j = 0; j < i; j++) {
      a = price[i] - price[j];

      if (max < a) {
        max = a;
      }
    }
  }
  return max;
}
int main(void) {
  int n;
  cin >> n;

  vector<int> price(n);

  for (int i = 0; i < n; i++) {

    cin >> price[i];
  }

  int max = max_profit(price);

  cout << max << endl;
  return 0;
}

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

int max_profit(vector<int> &price) {
  int profit;
  long long int max = -999999999;
  int min = 1;
  for (int i = 1; i <= price.size() - 1; i++) {

    if (i == 1) {
      min = price[0];
    } else if (min >= price[i - 1]) {
      min = price[i - 1];
    }

    profit = price[i] - min;

    if (max < profit) {
      max = profit;
    }
  }
  return max;
}
int main(void) {
  int n;
  cin >> n;

  vector<int> price(n);

  for (int i = 0; i < n; i++) {

    cin >> price[i];
  }

  int max = max_profit(price);

  cout << max << endl;
  return 0;
}


#include <iostream>
#include <limits.h>
#include <stdlib.h>

using namespace std;

int main() {
  int n, *nums, max = INT_MIN, preMin = INT_MAX;
  cin >> n;
  nums = (int *)malloc(sizeof(int) * n);

  for (int i = 0; i < n; i++) {
    cin >> nums[i];
  }

  for (int i = 0; i < n - 1; i++) {
    if (nums[i] >= preMin)
      continue;
    for (int j = (i + 1); j < n; j++) {
      if (max < (nums[j] - nums[i])) {
        max = (nums[j] - nums[i]);
      }
    }
  }

  cout << max << endl;
  free(nums);
  return 0;
}

#include <iostream>
#include <limits.h>

using namespace std;

int main() {
  int n, nextNum, max = INT_MIN, preMin = INT_MAX;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> nextNum;
    if (nextNum - preMin > max) {
      max = nextNum - preMin;
    }
    if (nextNum < preMin)
      preMin = nextNum;
  }

  cout << max << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, MAX = -2000000000;
  cin >> N;
  vector<int> R(N);
  for (int i = 0; i < N; i++)
    cin >> R.at(i);

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (MAX < (R.at(j) - R.at(i)))
        MAX = R.at(j) - R.at(i);
    }
  }
  cout << MAX << endl;
}

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;
}


#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n;
  int t[200000];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &t[i]);
  }
  int ans = -1e9;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = max(ans, t[j] - t[i]);
    }
  }
  cout << ans << "\\n";
  return 0;
}

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int r, m = -1e9, min;
  int N;
  cin >> N;
  cin >> min;
  for (int j = 0; j < N - 1; j++) {
    cin >> r;
    if (r - min > m)
      m = r - min;
    if (min > r)
      min = r;
  }
  cout << m << "\\n";
  return 0;
}


#include <iostream>
#include <limits.h>
#include <vector>

using namespace std;
vector<int> n;
int main(void) {
  int count = 0, num, ans = INT_MIN, cn;
  cin >> count;
  for (int i = 0; i < count; i++) {
    cin >> num;
    n.push_back(num);
  }
  count = n.size();
  for (int j = 0; j < count - 1; j++)
    for (int i = j + 1; i < count; i++) {
      cn = n.at(i) - n.at(j);
      ans = cn >= ans ? cn : ans;
    }
  cout << ans << endl;
  return 0;
}

#include <cstdio>
#include <iostream>
using namespace std;
int a[200010];
int main() {
  int n, minh, maxh = -2000000000;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  minh = a[0];
  for (int i = 1; i < n; i++) {
    maxh = max(maxh, a[i] - minh);
    minh = min(minh, a[i]);
  }
  printf("%d\\n", maxh);
  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, m;
  vector<int> v1, v2;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m;
    v1.push_back(m);
  }
  for (int i = 1; (v1.end() - i) != v1.begin(); i++) {
    v2.push_back(*(v1.end() - i) - *min_element(v1.begin(), v1.end() - i));
  }
  int ans = *max_element(v2.begin(), v2.end());
  cout << ans << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, m;
  vector<int> v1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m;
    v1.push_back(m);
  }
  int MIN = v1[0], ans = v1[1] - v1[0];
  for (int i = 2; v1.begin() + i != v1.end(); i++) {
    MIN = min(MIN, v1[i - 1]);
    ans = max(ans, v1[i] - MIN);
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int M(vector<int> A) {
  int m = 0;
  bool flag = true;
  int d = A[1] - A[0];
  while (1) {
    for (int i = m + 1; i < A.size(); i++) {
      flag = true;
      if (A[i] - A[m] < 0) {
        m = i;
        flag = false;
        break;
      }
      if (A[i] - A[m] > d) {
        d = A[i] - A[m];
      }
    }
    if (flag == true)
      break;
  }
  return d;
}

int main() {
  int n;
  cin >> n;
  vector<int> A;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    A.push_back(a);
  }
  cout << M(A) << endl;
  return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int M(vector<int> A) {
  int m = 0;
  int c = 0;
  int d = A[1] - A[0];
  while (1) {
    for (int i = m + 1; i < A.size(); i++) {
      c++;
      if (A[i] - A[m] < 0) {
        m = i;
        break;
      }
      if (A[i] - A[m] > d) {
        d = A[i] - A[m];
      }
    }
    if (c >= A.size() - 1)
      break;
  }
  return d;
}

int main() {
  int n;
  cin >> n;
  vector<int> A;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    A.push_back(a);
  }
  cout << M(A) << endl;
  return 0;
}


#include <iostream>

using namespace std;

int main() {
  int n;

  cin >> n;

  int *a = new int[n];

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int max = -2147483647;
  int result = 0;
  for (int i = n - 1; i > 0; i--) {
    for (int j = i - 1; j >= 0; j--) {
      result = a[i] - a[j];
      if (result > max)
        max = result;
    }
  }

  cout << max << endl;

  return 0;
}

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int n;
  int a[200000];

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int maxv = -2147483647;
  int minv = a[0];
  for (int i = 1; i < n; i++) {
    maxv = max(maxv, a[i] - minv);
    minv = min(minv, a[i]);
  }

  cout << maxv << endl;

  return 0;
}


#include <climits>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int num;
  cin >> num;

  std::vector<int> r_t;
  for (int i = 0; i < num; i++) {
    int n;
    cin >> n;
    r_t.push_back(int(n));
  }

  int max_value = INT_MIN;
  for (int i = 0; i < num - 1; i++) {
    for (int j = i + 1; j < num; j++) {
      if (r_t[j] - r_t[i] > max_value) {
        max_value = r_t[j] - r_t[i];
      }
    }
  }

  cout << max_value << endl;
}

#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

using namespace std;

static const int MAX = 200000;

int main() {
  int R[MAX];
  int num;

  cin >> num;
  for (int i = 0; i < num; i++)
    cin >> R[i];

  int maxv = INT_MIN;
  int minv = R[0];

  for (int i = 1; i < num; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int n, R[200001], max = -1e9;
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> R[i];

  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int d = R[j] - R[i];
      if (d > max)
        max = d;
    }
  }

  cout << max << endl;

  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int n, R[200001], min = 2e9, max = -2e9;
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> R[i];

  for (int i = 0; i < n; ++i) {
    if (R[i] - min > max)
      max = R[i] - min;
    if (R[i] < min)
      min = R[i];
  }

  cout << max << endl;

  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  long n;
  cin >> n;
  long long S[200001];
  int i, k;
  long long ans = -1000000001;
  for (i = 0; i < n; i++) {
    cin >> S[i];
  }

  for (i = 0; i < n; i++) {
    for (k = i + 1; k < n; k++) {
      if (S[k] - S[i] > ans) {
        ans = S[k] - S[i];
      }
    }
  }
  cout << ans << endl;
}

#include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  long n;
  cin >> n;
  long long S[200001];
  int i, k;
  long long ans = -1000000001;

  for (i = 0; i < n; i++) {
    cin >> S[i];
  }
  long long minimum = S[0];

  for (i = 1; i < n; i++) {
    ans = max(ans, S[i] - minimum);
    minimum = min(minimum, S[i]);
  }
  cout << ans << endl;
}


#include <iostream>
#include <vector>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;

  vector<long> nums(n);
  for (int i = 0; i < n; i++)
    cin >> nums[i];

  long ans = nums[1] - nums[0];
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = max(ans, nums[j] - nums[i]);
    }
  }

  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;

  int input;
  int min = INT_MAX, max = INT_MIN;

  for (int i = 0; i < n; i++) {
    cin >> input;

    if (max < input - min)
      max = input - min;
    if (min > input)
      min = input;
  }

  cout << max << endl;

  return 0;
}


#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int R[N + 5];
  int maxn = -999999999;
  for (int t = 0; t < N; t++) {
    cin >> R[t];

    if (t > 0) {
      for (int i = 0; i < t; i++) {
        maxn = max(R[t] - R[i], maxn);
      }
    }
  }
  cout << maxn << endl;
  return 0;
}

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int R[N + 5];
  int maxn = -999999999;
  for (int t = 0; t < N; t++) {
    cin >> R[t];
  }
  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < N; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }
  cout << maxv << endl;
  return 0;
}


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265

int main(void) {
  int max = -1000000000;
  int n;
  int *data;
  cin >> n;
  data = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> data[i];
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (data[j] - data[i] > max)
        max = data[j] - data[i];
    }
  }
  cout << max << endl;
  delete[] data;
  return 0;
}

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265

int main(void) {
  int max = -1000000000;
  int n;
  int min, data;
  cin >> n;
  cin >> min;
  for (int i = 0; i < n - 1; i++) {
    cin >> data;
    if (data - min > max)
      max = data - min;
    if (min > data)
      min = data;
  }
  cout << max << endl;
  return 0;
}


#include <iostream>
using namespace std;

int main() {

  int n, R[200000], cost;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> R[i];
    if (i == 1)
      cost = R[i] - R[i - 1];
    if (i > 1) {
      for (int j = 0; j < i; j++) {
        if (cost < R[i] - R[j]) {
          cost = R[i] - R[j];
        }
      }
    }
  }

  cout << cost << endl;

  return 0;
}

#include <stdio.h>

int main(void) {

  int x[200000];
  int n, i, j;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  int max = -1000000000, min = x[0];
  for (j = 1; j < n; j++) {
    if (x[j] - min > max)
      max = x[j] - min;
    if (min > x[j])
      min = x[j];
  }
  printf("%d\\n", max);
  return 0;
}


#include <iostream>
using namespace std;

int main(void) {
  int num;
  int input;
  int lst[200000];
  int head;
  int tail;

  cin >> num;
  for (int i = 0; i < num; i++) {
    cin >> lst[i];
  }

  int between = lst[1] - lst[0];
  int max = lst[1] - lst[0];
  for (int i = 0; i < num; i++) {
    for (int j = i + 1; j < num; j++) {
      between = lst[j] - lst[i];
      if (between > max)
        max = between;
    }
  }

  cout << max << "\\n";
}

#include <algorithm>
#include <iostream>
using namespace std;

int main(void) {
  int num;
  int input;
  int lst[200000];
  int small;
  int large;
  int maximum;
  cin >> num;
  for (int i = 0; i < num; i++) {
    cin >> lst[i];
  }
  maximum = -2000000000;
  small = lst[0];
  large = lst[0];

  for (int i = 1; i < num; i++) {
    maximum = max(maximum, lst[i] - small);
    small = min(small, lst[i]);
  }
  cout << maximum << endl;
}


#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int count = 0;
  int a[200000];
  int buy = 100000000;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int sell = 0;
  int total = -1000000000;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      total = max(total, a[j] - a[i]);
    }
  }
  /*    for(int i=0;i<n;i++){
          cout << a[i][1] << a[i][0] << endl;
      }*/

  cout << total << endl;
  return 0;
}

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[200000];
  int minid[200000];
  int total = -1000000000;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      continue;
    if (a[minid[i - 1]] > a[i]) {
      minid[i] = i;
    } else {
      minid[i] = minid[i - 1];
    }
    total = max(total, a[i] - a[minid[i - 1]]);
  }
  cout << total << endl;
  return 0;
}


#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define mod 1000000007
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> R(n);
  rep(i, n) cin >> R[i];

  int ans = -mod;
  rep(i, n) {
    for (int j = i + 1; j < n; ++j) {
      ans = max(ans, R[j] - R[i]);
    }
  }
  cout << ans << endl;
}

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define mod 1000000007
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> R(n);
  rep(i, n) cin >> R[i];

  int maxV = -2000000000;
  int minV = R[0];
  for (int i = 1; i < n; ++i) {
    maxV = max(maxV, R[i] - minV);
    minV = min(minV, R[i]);
  }
  cout << maxV << endl;
}


#include <iostream>

using namespace std;

int main() {
  int max;
  int cnt;
  int num[2000000] = {};
  cin >> cnt;
  for (int i = 0; i < cnt; i++) {
    cin >> num[i];
  }
  max = num[1] - num[0];
  for (int i = 0; i < cnt - 1; i++) {
    for (int j = i + 1; j < cnt; j++) {
      if ((num[j] - num[i]) > max) {
        max = num[j] - num[i];
      }
    }
  }
  cout << max << endl;
}

#include <algorithm>
#include <climits>
#include <iostream>
using namespace std;

int main() {
  int n;
  int mn = INT_MAX;
  int ans = INT_MIN;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    ans = max(ans, t - mn);
    mn = min(t, mn);
  }
  cout << ans << endl;
}


#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 2000000000;

int main() {
  int R[MAX], n;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];

  int maxv = -20000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 2000000;

int main() {
  int R[MAX], n;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n, ans = -1000000000;
  cin >> n;
  int *p = new int[n];

  for (int i = 0; i < n; i++)
    cin >> p[i];

  for (int i = n - 1; i > 0; i--) {
    for (int j = i - 1; j >= 0; j--) {
      if ((p[i] - p[j]) > ans)
        ans = p[i] - p[j];
    }
  }
  cout << ans << "\\n";
  delete[] p;
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int n, max = -1000000000, min;
  cin >> n;
  cin >> min;
  int x;

  for (int i = 1; i < n; i++) {
    cin >> x;
    if ((x - min) > max)
      max = x - min;
    if (min > x)
      min = x;
  }

  cout << max << "\\n";
  return 0;
}


#include <iostream>
#define INT_MIN -2000000000
#define MAX_R 200001
using namespace std;

int main() {
  int n, k;
  while (cin >> n) {
    int max = INT_MIN;
    int r[MAX_R];
    k = n;
    while (k--) {
      cin >> r[k];
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (r[i] - r[j] > max)
          max = r[i] - r[j];
      }
    }
    cout << max << endl;
  }
  return 0;
}

#include <iostream>
#define INT_MIN -2000000000
#define MAX_R 200001
using namespace std;

int main() {
  int n, k;
  while (cin >> n) {
    int max = INT_MIN;
    int r[MAX_R];
    k = n;
    while (k--) {
      cin >> r[k];
    }
    for (int i = 0; i < n; i++) {
      if (r[i] < max)
        continue;
      for (int j = i + 1; j < n; j++) {
        if (r[i] - r[j] > max)
          max = r[i] - r[j];
      }
    }
    cout << max << endl;
  }
  return 0;
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> rs(n);
  for (auto &r : rs) {
    cin >> r;
  }

  int ans = INT_MIN;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = max(ans, rs[j] - rs[i]);
    }
  }
  cout << ans << endl;
}

#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> rs(n);
  for (auto &r : rs) {
    cin >> r;
  }

  int ans = INT_MIN;
  int min_r = rs[0];
  for (int i = 1; i < n; i++) {
    ans = max(ans, rs[i] - min_r);
    min_r = min(min_r, rs[i]);
  }
  cout << ans << endl;
}


#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define rloop(i, a, b) for (int i = a; i >= b; i--)
const int inf = 1e8;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009

int main() {
  int n;
  cin >> n;
  vector<ll> r(n);
  loop(i, 0, n) { cin >> r[i]; }
  ll M = -1 * INF;
  ll m = r[0];
  loop(i, 0, n - 1) {
    if (r[i] == m) {
      vector<ll> r2(n);
      r2 = r;
      sort(r2.begin() + i + 1, r2.end());
      m = r2.back();
    }
    M = max(M, m - r[i]);
  }
  cout << M << "\\n";
}

#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define rloop(i, a, b) for (int i = a; i >= b; i--)
const int inf = 1e8;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009

int main() {
  int n;
  cin >> n;
  vector<ll> r(n);
  loop(i, 0, n) { cin >> r[i]; }
  ll M = -1 * INF;
  ll m = r[0];
  loop(i, 1, n) {
    m = min(m, r[i - 1]);
    M = max(M, r[i] - m);
  }
  cout << M << "\\n";
}


#include <iostream>
using namespace std;

int main() {

  int size, max, sa;

  cin >> size;

  int *array = new int[size];

  for (int i = 0; i < size; i++) {
    cin >> array[i];
  }

  max = array[size - 1] - array[0];

  for (int i = size - 1; i >= 0; i--) {
    for (int j = 0; j < i; j++) {
      sa = array[i] - array[j];
      if (max < sa) {
        max = sa;
      }
    }
  }

  cout << max << "\\n";

  delete[] array;
  return 0;
}

#include <iostream>
using namespace std;

int main() {

  int size, max, sa;

  cin >> size;

  int *array = new int[size];

  for (int i = 0; i < size; i++) {
    cin >> array[i];
  }

  max = -2000000000;

  int minv = array[0];

  for (int i = 1; i < size; i++) {
    if (max < array[i] - minv) {
      max = array[i] - minv;
    }
    if (minv > array[i]) {
      minv = array[i];
    }
  }

  cout << max << "\\n";

  delete[] array;
  return 0;
}


#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  int Rt[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", Rt + i);
  }

  int max = Rt[1] - Rt[0];
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < i; k++) {
      if (Rt[i] - Rt[k] > max) {
        max = Rt[i] - Rt[k];
      }
    }
  }
  printf("%d\\n", max);

  return 0;
}

#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  int Rt[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", Rt + i);
  }

  int maxValue = Rt[1] - Rt[0];
  int min = Rt[0];

  for (int i = 0; i < n; i++) {
    if (Rt[i] < min) {
      min = Rt[i];
    } else {
      if ((Rt[i] - min) > maxValue && i != 0) {
        maxValue = Rt[i] - min;
      }
    }
  }

  printf("%d\\n", maxValue);

  return 0;
}


#include <climits>
#include <iostream>

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  int r[n];
  for (int t = 0; t <= n - 1; t++) {
    std::cin >> r[t];
  }
  int max;
  max = INT_MIN;
  for (int i = 0; i <= n - 2; i++) {
    for (int j = i + 1; j <= n - 1; j++) {
      if (max < r[j] - r[i]) {
        max = r[j] - r[i];
      }
    }
  }
  std::cout << max << std::endl;

  return 0;
}

#include <climits>
#include <iostream>

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  int r[n];
  for (int t = 0; t <= n - 1; t++) {
    std::cin >> r[t];
  }
  int max;
  int min;
  max = INT_MIN;
  min = r[0];
  for (int j = 1; j <= n - 1; j++) {
    max = std::max(max, r[j] - min);
    min = std::min(min, r[j]);
  }
  std::cout << max << std::endl;

  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n, r[200010], max = -2e9;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (r[j] - r[i] > max)
        max = r[j] - r[i];
    }
  }

  cout << max << endl;
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int n, r[200010], max = -2e9, rmin = 2e9;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }

  for (int i = 0; i < n; i++) {
    if (r[i] < rmin) {
      rmin = r[i];
      for (int j = i + 1; j < n; j++) {
        if (r[j] - r[i] > max)
          max = r[j] - r[i];
      }
    }
  }

  cout << max << endl;
  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;

  cin >> n;
  for (int i = 0; i = n; i++)
    cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}


#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[20000];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int maxn = a[1] - a[0];
  for (int j = 1; j <= n - 1; j++)
    for (int i = 0; i < j; i++) {
      if (a[j] - a[i] > maxn)
        maxn = a[j] - a[i];
    }
  cout << maxn << endl;
}

#include <iostream>
using namespace std;
int a[200000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int min = a[0];
  int maxn = a[1] - a[0];
  for (int j = 1; j < n; j++) {
    if (a[j] - min > maxn)
      maxn = a[j] - min;
    if (a[j] < min)
      min = a[j];
  }
  cout << maxn << endl;
}


#include <bits/stdc++.h>
using namespace std;
long long n, a[1000000], x, y, mi, an;
int main() {
  cin >> n;
  for (x = 0; x < n; x++) {
    cin >> a[x];
    for (y = x - 1; y >= 0; y--) {
      if (x == 1) {
        mi = a[x];
      }
      if (a[x] < mi) {
        mi = a[x];
      }
      if (x == 1 && y == 0) {
        an = a[x] - a[y];
      }
      if (an < a[x] - a[y]) {
        an = a[x] - a[y];
      }
    }
  }
  cout << an << endl;
}

#include <bits/stdc++.h>
using namespace std;
long long n, a[1000000], x, y, mi, an;
int main() {
  cin >> n;
  for (x = 0; x < n; x++) {
    cin >> a[x];
    if (x == 1) {
      an = a[x] - a[x - 1];
    }
    if (x == 0) {
      mi = a[x];
    }
    if (an < a[x] - mi) {
      an = a[x] - mi;
    }
    if (mi > a[x]) {
      mi = a[x];
    }
  }
  cout << an << endl;
}


#include <stdio.h>

int main(void) {
  int i = 0;
  int n = 0;
  int min;
  int now;
  int max_margin = -2147483648;
  int margin;

  scanf("%d", &n);
  scanf("%d", &min);
  for (i = 1; i < n; i++) {
    scanf("%d", now);
    margin = now - min;
    if (margin > max_margin) {
      max_margin = margin;
    }
    if (now < min) {
      min = now;
    }
  }
  printf("%d\\n", max_margin);

  return 0;
}

#include <stdio.h>

int main(void) {
  int i = 0;
  int n = 0;
  int min;
  int now;
  int max_margin = -2147483648;
  int margin;

  scanf("%d", &n);
  scanf("%d", &min);
  for (i = 1; i < n; i++) {
    scanf("%d", &now);
    margin = now - min;
    if (margin > max_margin) {
      max_margin = margin;
    }
    if (now < min) {
      min = now;
    }
  }
  printf("%d\\n", max_margin);

  return 0;
}


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;

  vector<ll> R(n);
  rep(i, n) cin >> R[i];

  ll ans = -1001001001001;

  rep(i, n) for (int j = i + 1; j < n; j++) ans =
      (R[j] - R[i] > ans ? R[j] - R[i] : ans);

  cout << ans << endl;
}

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> R(n);
  rep(i, n) cin >> R[i];

  ll maxv = R[1] - R[0];
  ll minv = R[0];

  for (int j = 1; j < n; j++) {
    maxv = maxv > R[j] - minv ? maxv : R[j] - minv;
    minv = minv < R[j] ? minv : R[j];
  }

  cout << maxv << endl;
}


#include <array>
#include <iostream>
#include <limits>

using namespace std;

int main() {
  int len;
  cin >> len;
  array<int, 200000> nums;

  for (int i = 0; i < len; i++)
    cin >> nums[i];

  int diffMax = numeric_limits<int>::min();
  for (int i = 0; i < len - 1; i++) {
    for (int j = i + 1; j < len; j++) {
      if (nums[j] - nums[i] > diffMax)
        diffMax = nums[j] - nums[i];
    }
  }

  cout << diffMax << endl;

  return 0;
}

#include <array>
#include <iostream>
#include <limits>

using namespace std;

int main() {
  int len;
  cin >> len;
  array<int, 200000> nums;

  for (int i = 0; i < len; i++)
    cin >> nums[i];

  int mi = nums[0];
  int diffMax = numeric_limits<int>::min();
  for (int i = 1; i < len; i++) {
    diffMax = max<int>(diffMax, nums[i] - mi);
    mi = min<int>(mi, nums[i]);
  }

  cout << diffMax << endl;

  return 0;
}


#include <cstdlib>
#include <iostream>
#include <vector>

void max_dif(std::vector<int> R, int n);
std::vector<int> insertionSort(std::vector<int> A, int N, int th);
void print(std::vector<int> A, int N);

int main(void) {
  int n;
  std::cin >> n;
  std::vector<int> R(n);
  for (int i = 0; i < n; i++) {
    std::cin >> R[i];
  }
  max_dif(R, n);
  return EXIT_SUCCESS;
}

void max_dif(std::vector<int> R, int n) {
  std::vector<int> A(n, 0);
  int dif = R[1] - R[0];
  int temp;
  for (int i = 1; i < n; i++) {
    A = insertionSort(R, n, i);
    temp = A[n - 1] - A[i - 1];
    if (temp > dif) {
      dif = temp;
    }
  }
  std::cout << dif << std::endl;
  return;
}

std::vector<int> insertionSort(std::vector<int> A, int N, int th) {
  int v;
  int j;
  for (int i = th + 1; i <= N - 1; i++) {
    v = A[i];
    j = i - 1;
    while (j >= th && A[j] > v) {
      A[j + 1] = A[j];
      j--;
      A[j + 1] = v;
    }
  }
  return A;
}

void print(std::vector<int> A, int N) {
  for (int i = 0; i < N - 1; i++) {
    std::cout << A[i] << " ";
  }
  std::cout << A[N - 1] << std::endl;
}

#include <cstdlib>
#include <iostream>
#include <vector>
#define MIN -1000000000

void min(std::vector<int> R, int n) {
  int maxv = MIN;
  int minv = R[0];
  int dif;

  for (int j = 1; j < n; j++) {
    dif = R[j] - minv;
    if (dif > maxv) {
      maxv = dif;
    }
    if (R[j] < minv) {
      minv = R[j];
    }
  }
  std::cout << maxv << std::endl;
  return;
}

int main(void) {
  int n;
  std::cin >> n;
  std::vector<int> R(n);
  for (int i = 0; i < n; i++) {
    std::cin >> R[i];
  }
  min(R, n);
  return EXIT_SUCCESS;
}


#include <cmath>
#include <iostream>
using namespace std;

int main() {

  int n, i, j, l, answer = 0;
  cin >> n;
  int A[n];
  for (int u = 0; u < n; u++) {
    cin >> l;
    A[u] = l;
  }
  answer = A[1] - A[0];
  for (int s = 2; s < n; s++) {
    i = A[s];
    for (int t = 0; t < s; t++) {
      j = A[t];
      if ((i - j) > answer) {
        answer = i - j;
      }
    }
  }
  cout << answer << endl;
  return 0;
}

#include <iostream>
using namespace std;

int rt[200000];

int main() {
  ios::sync_with_stdio(false);
  int n;
  int i, j;
  int max, min;
  cin >> n;
  max = 0x80000000;
  for (i = 0; i < n; i++) {
    cin >> rt[i];
  }
  min = rt[0];
  for (i = 1; i < n; i++) {
    if ((rt[i] - min) > max) {
      max = rt[i] - min;
    }
    if ((rt[i]) < min) {
      min = rt[i];
    }
  }
  cout << max << endl;
  return 0;
}


// #define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, x, n) for (int i = x; i < (int)n; ++i)
#define repi(i, n) for (int i = 0; i <= (int)n; ++i)
#define REPI(i, x, n) for (int i = x; i <= (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) != (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
#pragma endregion

// Effective std
#pragma region ESTD

template <typename C, typename T> constexpr int count(C &c, T t) {
  return count(ALL(c), t);
}

template <typename C, typename F> constexpr int count_if(C &c, F f) {
  return count_if(ALL(c), f);
}

template <typename C, typename T, typename U>
constexpr void replace(C &c, T t, U u) {
  replace(ALL(c), t, u);
}

template <typename C, typename F, typename U>
constexpr void replace_if(C &c, F f, U u) {
  (ALL(c), f, u);
}

template <typename C> constexpr void sort(C &c) { sort(ALL(c)); }

template <typename C, typename Pred> constexpr void sort(C &c, Pred p) {
  sort(ALL(c), p);
}

#pragma endregion

// ??°?????????????????¬??????
#pragma region GRAPH

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {}
};

bool operator<(const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight
         : e.src != f.src     ? e.src < f.src
                              : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

#pragma endregion

// ?´???°
#pragma region PRIME
bool is_prime(unsigned n) {
  switch (n) {
  case 0:
  case 1:
    return false;
  case 2:
    return true;
  }
  if (n % 2 == 0)
    return false;
  for (unsigned i = 3; i * i <= n; i += 2)
    if (n % i == 0)
      return false;
  return true;
}
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2 * acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9 + 7)
#pragma endregion

int main() {
  int n;
  cin >> n;
  vi v;
  rep(i, n) {
    int x;
    cin >> x;
    v.push_back(x);
  }

  ll ans = -999999999999999;
  rep(i, n) {
    if (i == n - 1)
      break;
    if (i > 0 && v[i] >= v[i - 1])
      continue;
    REP(j, i + 1, n) {
      if (v[j] - v[i] > ans)
        ans = v[j] - v[i];
    }
  }
  P(ans);

  return 0;
}

// #define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, x, n) for (int i = x; i < (int)n; ++i)
#define repi(i, n) for (int i = 0; i <= (int)n; ++i)
#define REPI(i, x, n) for (int i = x; i <= (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) != (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
#pragma endregion

// Effective std
#pragma region ESTD

template <typename C, typename T> constexpr int count(C &c, T t) {
  return count(ALL(c), t);
}

template <typename C, typename F> constexpr int count_if(C &c, F f) {
  return count_if(ALL(c), f);
}

template <typename C, typename T, typename U>
constexpr void replace(C &c, T t, U u) {
  replace(ALL(c), t, u);
}

template <typename C, typename F, typename U>
constexpr void replace_if(C &c, F f, U u) {
  (ALL(c), f, u);
}

template <typename C> constexpr void sort(C &c) { sort(ALL(c)); }

template <typename C, typename Pred> constexpr void sort(C &c, Pred p) {
  sort(ALL(c), p);
}

#pragma endregion

// ??°?????????????????¬??????
#pragma region GRAPH

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {}
};

bool operator<(const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight
         : e.src != f.src     ? e.src < f.src
                              : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

#pragma endregion

// ?´???°
#pragma region PRIME
bool is_prime(unsigned n) {
  switch (n) {
  case 0:
  case 1:
    return false;
  case 2:
    return true;
  }
  if (n % 2 == 0)
    return false;
  for (unsigned i = 3; i * i <= n; i += 2)
    if (n % i == 0)
      return false;
  return true;
}
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2 * acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9 + 7)
#pragma endregion

int main() {
  int n, min;
  int ans = INT_MIN;
  cin >> n;
  cin >> min;
  rep(i, n - 1) {
    int x;
    cin >> x;
    int p = x - min;
    if (p > ans)
      ans = p;
    if (x < min)
      min = x;
  }
  P(ans);

  return 0;
}


#include <algorithm>
#include <cassert>
#include <iostream>
using namespace std;

const int INF = 1 << 29;
int n, r[200000];

void solve() {
  int ans = -INF, pos = 0;
  for (int i = 1; i < n; i++) {
    ans = max(ans, r[i] - r[pos]);
    if (r[pos] > r[i]) {
      pos = i;
    }
  }
  assert(ans != -INF);
  cout << ans << endl;
}

int main() {
  while (cin >> n) {
    for (int i = 0; i < n; i++)
      cin >> r[i];
    solve();
  }
}

#include <algorithm>
#include <cassert>
#include <iostream>
using namespace std;

const int INF = 1 << 30;
int n, r[200000];

void solve() {
  int ans = -INF, pos = 0;
  for (int i = 1; i < n; i++) {
    ans = max(ans, r[i] - r[pos]);
    if (r[pos] > r[i]) {
      pos = i;
    }
  }
  cout << ans << endl;
}

int main() {
  while (cin >> n) {
    for (int i = 0; i < n; i++)
      cin >> r[i];
    solve();
  }
}


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<double> r(n);
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }
  double max_profit = -1000000000;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      max_profit = max(max_profit, r[j] - r[i]);
    }
  }
  cout << setprecision(10) << max_profit << endl;
}

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<double> r(n);
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }
  double max_profit = -1000000000;
  double min_r = r[0];
  for (int i = 1; i < n; i++) {
    min_r = min(min_r, r[i - 1]);
    max_profit = max(max_profit, r[i] - min_r);
  }
  cout << setprecision(10) << max_profit << endl;
}


#include <cstdio>
#include <iostream>
using namespace std;

const int MAXN = 200001;

int main(int argc, char *argv[]) {
  int n;
  int A[MAXN];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  int max = -1000000000;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int temp = A[j] - A[i];
      if (temp > max) {
        max = temp;
      }
    }
  }
  printf("%d\\n", max);
  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 2000000;
int main(int argc, char *argv[]) {
  int R[MAX], n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> R[i];
  }

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}


#include <cmath>
#include <iostream>

using namespace std;

int main() {
  long long n, i, max = -9999999999, j;
  cin >> n;
  long long R[n];
  for (i = 0; i < n; ++i) {
    cin >> R[i];
    for (j = 0; j < i; ++j) {
      if (R[i] - R[j] > max) {
        max = R[i] - R[j];
      }
    }
  }
  cout << max << endl;
  return 0;
}

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  long long n, i, max = -9999999999, Rmin = 9999999999;
  cin >> n;
  long long R[n];
  for (i = 0; i < n; ++i) {
    cin >> R[i];
    if (i > 0 && R[i] - Rmin > max) {
      max = R[i] - Rmin;
    }
    if (R[i] < Rmin)
      Rmin = R[i];
  }
  cout << max << endl;
  return 0;
}


#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int *r;
  r = new int[n];
  if (r == NULL) {
    cout << "Error!" << endl;
    return -1;
  }
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> r[i];
  }
  int max = r[1] - r[0];
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      if (r[j] - r[i] > max)
        max = r[j] - r[i];
    }
  }
  cout << max << endl;
  return 0;
}

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int *r;
  r = new int[n];
  if (r == NULL) {
    cout << "Error!" << endl;
    return -1;
  }
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> r[i];
  }
  int max = r[1] - r[0];
  for (j = n - 1; j >= 0; j--) {
    if (r[j] <= max)
      continue;
    for (i = j - 1; i >= 0; i--) {
      if (r[j] - r[i] > max)
        max = r[j] - r[i];
    }
  }
  cout << max << endl;
  return 0;
}


#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<ll> R(n);
  REP(i, n) cin >> R[i];
  ll res = R[1] - R[0];
  REP(i, n) FOR(j, i + 1, n) { res = max(res, R[j] - R[i]); }
  cout << res << "\\n";

  return 0;
}

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<ll> R(n);
  int max = INT_MIN;
  int min = INT_MAX;
  REP(i, n) {
    cin >> R[i];
    if (max < R[i] - min)
      max = R[i] - min;
    if (min > R[i])
      min = R[i];
  }
  cout << max << "\\n";

  return 0;
}


#include <climits>
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int max_prof(int r[], size_t s) {
  int t, max = r[1] - r[0];
  for (size_t i = 0; i < s; i++) {
    for (size_t j = i + 1; j < s; j++) {
      if ((t = r[j] - r[i]) > max)
        max = t;
    }
  }
  return max;
}

int main() {
  static_assert(1000000000 < INT_MAX, "");
  int n, r[200000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }
  cout << max_prof(r, n) << endl;
}

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int main() {
  int n, buf, minv, maxv;
  cin >> n;

  cin >> minv;
  cin >> buf;
  maxv = buf - minv;
  minv = std::min(minv, buf);

  for (int i = 0; i < n - 2; i++) {
    cin >> buf;
    maxv = std::max(maxv, buf - minv);
    minv = std::min(minv, buf);
  }
  cout << maxv << endl;
}


#include <algorithm>
#include <iostream>
using namespace std;

int N, A[200000];

int solve(void) {
  int maxp = 1 - 1000000000;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      maxp = max(maxp, A[j] - A[i]);
    }
  }
  return maxp;
}

int main(void) {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  cout << solve() << endl;

  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;

int N, A[200000];

int solve(void) {
  auto maxp = A[1] - A[0];
  auto minr = min(A[0], A[1]);
  for (auto i = 2; i < N; i++) {
    maxp = max(maxp, A[i] - minr);
    minr = min(minr, A[i]);
  }
  return maxp;
}

int main(void) {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  cout << solve() << endl;

  return 0;
}


#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>

using namespace std;

class c_fx {
private:
  int n;
  long t[200000];

public:
  void f_fx();
};

void c_fx::f_fx() {
  long i, j;
  long max_sa;

  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> t[i];
  }

  max_sa = t[n - 1] - t[n - 2];

  for (i = n - 1; i >= 0; --i) {
    for (j = i - 1; j >= 0; --j) {
      if (max_sa < t[i] - t[j]) {
        max_sa = t[i] - t[j];
      }
    }
  }

  cout << max_sa << endl;
}

int main() {
  c_fx fx01;

  fx01.f_fx();

  return 0;
}

#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>

using namespace std;

class c_fx {
private:
  int n;
  long t[200000];

public:
  void f_fx();
};

void c_fx::f_fx() {
  long i, j;
  long max_sa;
  long min_x;

  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> t[i];
  }

  max_sa = t[1] - t[0];
  min_x = t[0];

  for (j = 1; j < n; ++j) {
    if (max_sa < t[j] - min_x)
      max_sa = t[j] - min_x;
    if (min_x > t[j])
      min_x = t[j];
  }

  cout << max_sa << endl;
}

int main() {
  c_fx fx01;

  fx01.f_fx();

  return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int maxProfit(vector<int> &A, int N) {
  int maxProfit = 10 ^ 12 * (-1);
  int minR = A[0];
  for (int i = 1; i < N; i++) {
    maxProfit = max(maxProfit, A[i] - minR);
    minR = min(minR, A[i]);
  }
  return maxProfit;
}

int main() {
  int N;
  vector<int> A(N);
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];

  int sw = maxProfit(A, N);
  cout << sw << endl;
}

#include <iostream>
#include <vector>
using namespace std;

int maxProfit(vector<int> &A, int N) {
  int maxProfit = -2000000000;
  int minR = A[0];
  for (int i = 1; i < N; i++) {
    maxProfit = max(maxProfit, A[i] - minR);
    minR = min(minR, A[i]);
  }
  return maxProfit;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  int sw = maxProfit(A, N);
  cout << sw << endl;
}


#include <bits/stdc++.h>
#define int long long

#define MAX_N 200000

using namespace std;

signed main() {
  int n;
  int r[MAX_N];

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }

  int ans = r[1] - r[0];

  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j > i; j--) {
      ans = max(ans, r[j] - r[i]);
    }
  }

  cout << ans << endl;
}

#include <bits/stdc++.h>
#define int long long

#define MAX_N 200000

using namespace std;

signed main() {
  int n, r[MAX_N];

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> r[i];

  int minv = r[0];
  int maxv = r[1] - r[0];
  for (int i = 1; i < n; i++) {
    maxv = max(maxv, r[i] - minv);
    minv = min(minv, r[i]);
  }

  cout << maxv << endl;
}


#include <cstdio>
int d[200000 + 2];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &d[i]);

  int maxv = d[1] - d[0]; // 2 <= n < 200000
  int minv = d[0]; // Store a mininum value and get diff value with next value
                   // after next mininum
  for (int i = 1; i < n; i++) {
    maxv = (d[i] - minv > maxv) ? (d[i] - minv) : maxv;
    minv = (minv > d[i]) ? d[i] : minv;
  } //	local save history value

  printf("%d\\n", maxv);

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main() {
  int n = 0;
  fscanf(stdin, "%d", &n);
  vector<ll> v(n);
  for (int i = 0; i < n; ++i) {
    fscanf(stdin, "%lld", &v[i]);
  }
  ll ans = -INF;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      ans = max(ans, v[j] - v[i]);
    }
  }
  fprintf(stdout, "%lld\\n", ans);
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main() {
  int n = 0;
  fscanf(stdin, "%d", &n);
  vector<ll> v(n);
  for (int i = 0; i < n; ++i) {
    fscanf(stdin, "%lld", &v[i]);
  }
  ll ans = -INF;
  ll mn = v[0];
  for (int i = 1; i < n; ++i) {
    ans = max(ans, v[i] - mn);
    mn = min(mn, v[i]);
  }
  fprintf(stdout, "%lld\\n", ans);
  return 0;
}


#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <stdint.h>
#include <string>
#include <vector>

std::vector<int> nums;

int main(int argc, char *argv[]) {
  int N;

  std::cin >> N;

  for (int i = 0; i < N; i++) {
    int v;
    std::cin >> v;
    nums.push_back(v);
  }

  int maxDiff = -1000000000;
  for (int k = N - 1; k >= 0; k--) {
    for (int p = k - 1; p >= 0; p--) {
      if (nums[k] - nums[p] > maxDiff) {
        maxDiff = nums[k] - nums[p];
      }
    }
  }
  std::cout << maxDiff << std::endl;

  return 0;
}

#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <stdint.h>
#include <string>
#include <vector>

std::vector<int> nums;

int main(int argc, char *argv[]) {
  int N;

  std::cin >> N;

  for (int i = 0; i < N; i++) {
    int v;
    std::cin >> v;
    nums.push_back(v);
  }

  int maxDiff = -1000000000;
  int kmax = nums[N - 1] - 1;
  for (int k = N - 1; k >= 0; k--) {
    if (nums[k] <= kmax)
      continue;
    kmax = nums[k];
    for (int p = k - 1; p >= 0; p--) {
      if (nums[k] - nums[p] > maxDiff) {
        maxDiff = nums[k] - nums[p];
      }
    }
  }
  std::cout << maxDiff << std::endl;

  return 0;
}


#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <vector>
typedef int TInt;
typedef std::vector<TInt> TList;
TList Input() {
  int Count;
  std::cin >> Count;
  TList List(Count);
  for (int i = 0; i < Count; ++i) {
    std::cin >> List[i];
  }
  return List;
}
int main() {
  TList A = Input();
  assert(A.size() >= 2);
  int Profit = A[1] - A[0];
  int i = 0;
  while (i < A.size()) {
    int j = i + 1;
    for (int j = i + 1; j < A.size(); ++j) {
      int Diff = A[j] - A[i];
      if (Diff < 0) {
        i = j;
        break;
      }
      if (Diff > Profit)
        Profit = Diff;
    }
    if (j == A.size())
      break;
  }

  std::cout << Profit << std::endl;
  return 0;
}

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <vector>
typedef int TInt;
typedef std::vector<TInt> TList;
TList Input() {
  int Count;
  std::cin >> Count;
  TList List(Count);
  for (int i = 0; i < Count; ++i) {
    std::cin >> List[i];
  }
  return List;
}
int main() {
  TList A = Input();
  assert(A.size() >= 2);
  int Profit = A[1] - A[0];
  int i = 0;
  while (i < A.size()) {
    int j;
    for (j = i + 1; j < A.size(); ++j) {
      int Diff = A[j] - A[i];
      if (Diff < 0) {
        i = j;
        break;
      }
      if (Diff > Profit)
        Profit = Diff;
    }
    if (j == A.size())
      break;
  }

  std::cout << Profit << std::endl;
  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 20000;

int main() {
  int R[MAX], n;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = static_cast<int>(2e+5);
static const int MIN = static_cast<int>(1e+9);

int main() {
  int R[MAX], n;

  cin >> n;

  for (int i = 0; i < n; i++)
    cin >> R[i];

  int maxv = 1 - MIN;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int a[200010];

int main() {
  long long int i, j, maxn = -20000000000000, n, temp;
  cin >> n;
  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (i = 0; i < n - 1; i++)
    for (j = i + 1; j < n; j++) {
      temp = a[j] - a[i];
      maxn = max(maxn, temp);
    }
  cout << maxn << endl;
  return 0;
}

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int a[200010];

int main() {
  int n, i;
  cin >> n;
  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);
  int maxn = -1000000001;
  int minv = a[0];
  for (i = 1; i < n; i++) {
    maxn = max(a[i] - minv, maxn);
    minv = min(a[i], minv);
  }
  cout << maxn << endl;
  return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;

  long long int MAX = -10000000000;

  vector<long long int> r(n);
  for (int i = 0; i < n; i++)
    cin >> r[i];

  for (int i = n - 1; i >= 0; i--) {
    for (int j = 1; j <= i; j++) {
      if (MAX < (r[i] - r[i - j]))
        MAX = r[i] - r[i - j];
    }
  }

  cout << MAX << endl;

  return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;

  vector<long long int> r(n);
  for (int i = 0; i < n; i++)
    cin >> r[i];

  long long int Max = -10000000000;
  long long int Min = r[0];

  for (int i = 1; i < n; i++) {
    if (r[i] - Min > Max)
      Max = r[i] - Min;
    if (Min > r[i])
      Min = r[i];
  }

  cout << Max << endl;

  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int R[20000];

  for (int i = 0; i < n; i++)
    cin >> R[i];

  int min = 1000000000;
  int maxv = -1000000000;
  for (int i = 0; i < n - 1; i++) {
    if (min > R[i])
      min = R[i];
    if (maxv < R[i + 1] - min)
      maxv = R[i + 1] - min;
  }

  cout << maxv << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

int a[200001];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int mi = a[0];
  int ans = -1000000001;
  for (int i = 1; i < n; i++) {
    mi = min(mi, a[i - 1]);
    ans = max(ans, a[i] - mi);
  }
  cout << ans << endl;
  return 0;
}


#include <cmath>
#include <iostream>
#include <string>
#include <vector>

#define INF pow(10, 10)

using namespace std;

int main() {
  int cnt = 0;
  vector<int> R;
  R.push_back(INF);
  int Max = -INF;
  int n;
  cin >> cnt;
  for (int j = 0; j < cnt; j++) {
    cin >> n;
    R.push_back(n);

    for (int i = 0; i < R.size() - 1; i++) {
      int sub = R.back() - R[i];
      if (sub > Max) {
        Max = sub;
      }
    }

    // cout << "M: " << Max << endl;
  }

  cout << Max << endl;
}

#include <cmath>
#include <iostream>
#include <string>
#include <vector>

#define INF pow(10, 10)

using namespace std;

int main() {
  int cnt = 0;
  vector<int> R;
  int maxSub = -INF;
  int max = -INF;
  int min = INF;
  int n;
  cin >> cnt;
  for (int j = 0; j < cnt; j++) {
    cin >> n;
    R.push_back(n);

    int sub = n - min;
    if (sub > maxSub) {
      maxSub = sub;
    }

    // first time
    if (j == 0) {
      min = max = n;
      continue;
    }

    if (min > n) {
      min = n;
    }
    if (max < n) {
      max = n;
    }

    // for(int i=0;i<R.size()-1;i++){
    // int sub = R.back() - R[i];
    // if(sub > Max){
    //    Max = sub;
    //}
    //    }

    // cout << "M: " << Max << endl;
  }

  cout << maxSub << endl;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <time.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  int R[200010];
  for (int i = 0; i < n; i++) {
    cin >> R[i];
  }
  int max = R[1] - R[0];
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (R[j] - R[i] > max) {
        max = R[j] - R[i];
      }
    }
  }
  cout << max << endl;

  return 0;
}

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <time.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  int maxa = -2000000000;
  int minv;
  cin >> minv;
  int temp;

  for (int i = 1; i < n; i++) {
    cin >> temp;
    maxa = max(maxa, temp - minv);
    minv = min(minv, temp);
  }
  cout << maxa << endl;

  return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main() {
  int n_col;
  cin >> n_col;
  int *p_currency;
  p_currency = new int[n_col];
  int max_profit = -10000000000000;
  for (int i = 0; i < n_col; i++) {
    cin >> p_currency[i];

    for (int j = 0; j < i; j++) {
      int diff = p_currency[i] - p_currency[j];

      if (diff > max_profit) {
        max_profit = diff;
      }
    }
  }
  cout << max_profit << "\\n";
  delete[] p_currency;
  return 0;
}

#include <iostream>
#include <string>
using namespace std;

int main() {
  int n_col;
  cin >> n_col;
  int *p_currency;
  p_currency = new int[n_col];

  for (int i = 0; i < n_col; i++) {
    cin >> p_currency[i];
  }

  int max_profit = p_currency[1] - p_currency[0];
  // cout << "first max_profit: " << max_profit << "\\n";
  int min = p_currency[0];
  // cout << "first min: " << min << "\\n";

  for (int i = 1; i < n_col; i++) {
    int diff = p_currency[i] - min;
    if (max_profit < diff) {
      max_profit = diff;
    }

    if (min > p_currency[i]) {
      min = p_currency[i];
    }

    // cout << "min:" << min << "\\n";
    // cout << "max_profit: " << max_profit << "\\n";
  }
  cout << max_profit << "\\n";
  delete[] p_currency;
  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;

int main(void) {
  int N, R[MAX];
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> R[i];

  int maxv = -1000000000;

  for (int j = 1; j < N; j++)
    for (int i = 0; i < j; i++)
      maxv = max(maxv, R[j] - R[i]);

  cout << maxv << endl;

  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;

int main(void) {
  int N, R[MAX];
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> R[i];

  int maxv = -1000000000;
  int minr = R[0];

  for (int i = 1; i < N; i++) {
    maxv = max(maxv, R[i] - minr);
    minr = min(minr, R[i]);
  }

  cout << maxv << endl;

  return 0;
}


#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int solve(vector<int> list) {
  int max;
  for (int i = 0; i < list.size(); ++i) {
    for (int j = i + 1; j < list.size(); ++j) {
      int diff = list[j] - list[i];
      if (i == 0 && j == 1) {
        max = diff;
      }
      if (diff > max) {
        max = diff;
      }
    }
  }
  return max;
}

int main() {
  int N;
  cin >> N;
  vector<int> v;
  for (int i = 0; i < N; ++i) {
    string n;
    cin >> n;
    v.push_back(stoi(n));
  }
  cout << solve(v) << endl;
}

#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int solve(vector<int> list) {
  int diff_max;
  int tmp_max = 0;
  int tmp_max_num;
  for (int i = 0; i < list.size() - 1; ++i) {
    if (i == 0) {
      for (int j = 1; j < list.size(); ++j) {
        if (list[j] > tmp_max) {
          tmp_max = list[j];
          tmp_max_num = j;
        }
      }
      diff_max = tmp_max - list[i];
    } else if (i < tmp_max_num) {
      int diff = tmp_max - list[i];
      if (diff > diff_max) {
        diff_max = diff;
      }
    } else {
      tmp_max = 0;
      for (int j = i + 1; j < list.size(); ++j) {
        if (list[j] > tmp_max) {
          tmp_max = list[j];
          tmp_max_num = j;
        }
      }
      int diff = tmp_max - list[i];
      if (diff > diff_max) {
        diff_max = diff;
      }
    }
  }
  return diff_max;
}

int main() {
  int N;
  cin >> N;
  vector<int> v;
  for (int i = 0; i < N; ++i) {
    string n;
    cin >> n;
    v.push_back(stoi(n));
  }
  cout << solve(v) << endl;
}


#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, a[200000], ans = -1e9;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      ans = max(ans, a[j] - a[i]);
  cout << ans << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, a, ans = -1e9, amin = 1e9;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (i > 0)
      ans = max(a - amin, ans);
    amin = min(amin, a);
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int m[200000];
  for (int i = 0; i < n; i++) {
    cin >> m[i];
  }
  int max = m[1] - m[0];
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (max < m[j] - m[i])
        max = m[j] - m[i];
    }
  }
  cout << max << endl;
  return 0;
}

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int m[200000];
  for (int i = 0; i < n; i++) {
    cin >> m[i];
  }
  int max = -1000000000, min = m[0];
  for (int i = 1; i < n; i++) {
    if (max < m[i] - min)
      max = m[i] - min;
    if (m[i] < min)
      min = m[i];
  }
  cout << max << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[200001];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int ans = a[1] - a[0];
  for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++)
      if (ans < a[j] - a[i])
        ans = a[j] - a[i];
  cout << ans << endl;
  return 0;
}

#include <iostream>
using namespace std;
int main() {
  int n, a[200001] = {};
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int max = a[1] - a[0];
  int min = a[0];
  for (int i = 1; i < n; i++) {
    if (a[i] - min > max)
      max = a[i] - min;
    if (min > a[i])
      min = a[i];
  }
  cout << max << endl;
  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  int N;
  cin >> N;
  vector<int> v(N);
  cin >> v[0];
  for (int i = 1; i < N; i++) {
    cin >> v[i];
  }
  int maxv = -1000000007;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      maxv = max(maxv, v[j] - v[i]);
    }
  }
  cout << maxv << endl;
  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  int N;
  cin >> N;
  vector<long long> v(N);
  cin >> v[0];
  for (int i = 1; i < N; i++) {
    cin >> v[i];
  }
  long long maxv = -10000000007;
  long long minv = 10000000007;
  for (int i = 0; i < N; i++) {
    maxv = max(maxv, v[i] - minv);
    minv = min(minv, v[i]);
  }
  cout << maxv << endl;
  return 0;
}


#include <cstdio>
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int input_size, sub_max, temp;
  cin >> input_size;
  int array_num[input_size];

  for (int i = 0; i < input_size; ++i) {
    cin >> array_num[i];
  }

  for (int i = 0; i < input_size; ++i) {
    if (i == 0)
      sub_max = array_num[i + 1] - array_num[i];
    for (int j = i + 1; j < input_size; ++j) {
      temp = array_num[j] - array_num[i];
      if (temp > sub_max)
        sub_max = temp;
    }
  }

  printf("%d\\n", sub_max);

  return 0;
}

#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

const int MAX = (int)pow(10., 9.);
const int MIN = 1;

int main(int argc, char const *argv[]) {
  int input_size, num, temp, num_min;
  int sub_max = MIN - MAX;
  cin >> input_size;

  for (int i = 0; i < input_size; ++i) {
    cin >> num;
    if (i == 0) {
      num_min = num;
      continue;
    }
    temp = num - num_min;
    if (sub_max < temp)
      sub_max = temp;
    if (num_min > num)
      num_min = num;
  }

  printf("%d\\n", sub_max);

  return 0;
}


#include <stdio.h>
int main() {
  int i, n, j, max, r[200000];
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &r[i]);
  max = r[1] - r[0];
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (r[i] > r[j]) {
        i = j;
        continue;
      }
      if (r[j] - r[i] > max)
        max = r[j] - r[i];
    }
  }
  printf("%d\\n", max);
  return 0;
}


#include <iostream>

int main() {
  int number;
  std::cin >> number;

  int price[number];
  for (int i = 0; i < number; i++) {
    std::cin >> price[i];
  }

  int maximum = price[1] - price[0];
  int low_index = 0;
  int high_index = 1;
  for (int i = 0; i < number; i++) {
    for (int j = i + 1; j < number; j++) {
      if (maximum < price[j] - price[i]) {
        maximum = price[j] - price[i];
        high_index = j;
        low_index = i;
      }
    }
  }
  std::cout << maximum << std::endl;
}

#include <iostream>

int main() {
  int number;
  std::cin >> number;

  int price[number];
  for (int i = 0; i < number; i++) {
    std::cin >> price[i];
  }

  int maximum = price[1] - price[0];
  int low_index = 0;
  int high_index = 1;
  for (int i = 0; i < number; i++) {
    if (price[low_index] < price[i]) {
      continue;
    }
    for (int j = i + 1; j < number; j++) {
      if (price[j] < price[high_index] && i < high_index) {
        continue;
      }

      if (maximum < price[j] - price[i]) {
        maximum = price[j] - price[i];
        high_index = j;
        low_index = i;
      }
    }
  }
  std::cout << maximum << std::endl;
}


#include <iostream>
using namespace std;
int main() {
  int num, i, j, max_profit;
  cin >> num;
  int arr[num];
  for (i = 0; i < num; i++) {
    cin >> arr[i];
  }
  max_profit = arr[1] - arr[0];
  for (i = 0; i < num - 1; i++) {
    for (j = i + 1; j < num; j++) {
      if (max_profit < arr[j] - arr[i]) {
        max_profit = arr[j] - arr[i];
      }
    }
  }
  cout << max_profit << endl;
  return 0;
}

#include <iostream>
using namespace std;
int main() {
  int num, i, j, max_profit, min_val;
  cin >> num;
  int arr[num];
  for (i = 0; i < num; i++) {
    cin >> arr[i];
  }
  max_profit = arr[1] - arr[0];
  min_val = arr[0];
  for (i = 1; i < num; i++) {
    if (max_profit < arr[i] - min_val) {
      max_profit = arr[i] - min_val;
    }
    if (min_val > arr[i]) {
      min_val = arr[i];
    }
  }
  cout << max_profit << endl;
  return 0;
}


#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int p[200000];
int main() {
  int i, j, d = -1000000001, n;
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &p[i]);
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      d = max(d, p[j] - p[i]);
    }
  }
  printf("%d\\n", d);
  return 0;
}

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int p[200000] = {0};
int main() {
  int i, n, d = -1000000001, b;
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &p[i]);
  b = p[n - 1];
  for (i = n - 2; i >= 0; i--) {
    d = max(d, b - p[i]);
    if (b < p[i])
      b = p[i];
  }
  printf("%d\\n", d);
  return 0;
}


#include <iostream>
using namespace std;
static const int MAX = 200000;
int main() {
  int n;
  int R[MAX];
  cin >> n;
  if (n <= 1 || n > 200000)
    return 0;
  for (int i = 0; i < n; i++) {
    cin >> R[i];
  }
  int max = R[1] - R[0];
  for (int i = 1; i < n; i++)
    for (int j = 0; j < i; j++) {
      if (R[i] - R[j] > max)
        max = R[i] - R[j];
    }
  cout << max << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;
int main() {
  int R[MAX], n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> R[i];
  }
  int maxv = -2000000000;
  int minv = R[0];
  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }
  cout << maxv << endl;
  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 20000;

int main() {
  int n;
  int minv;
  int maxv = -2000000000;
  int R[MAX];

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> R[i];
  }
  minv = R[0];
  for (int j = 1; j < n; j++) {
    maxv = max(maxv, R[j] - minv);
    minv = min(minv, R[j]);
  }
  cout << maxv << endl;

  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;

int main() {
  int n;
  int minv;
  int maxv = -2000000000;
  int R[MAX];

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> R[i];
  }
  minv = R[0];
  for (int j = 1; j < n; j++) {
    maxv = max(maxv, R[j] - minv);
    minv = min(minv, R[j]);
  }
  cout << maxv << endl;

  return 0;
}


#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void input(vector<int> &, int &, int &);
int main() {
  vector<int> fx(200001);
  vector<bool> dp(1000000001, true);
  int dec = 0, n;
  int max, p;
  max = -1000000000;
  input(fx, n, max);
  for (int i = 0; i < n; ++i) {
    if (dp[i])
      dp[i] = false;
    else
      continue;
    for (int j = i + 1; j < n; ++j) {
      p = fx[j] - fx[i];
      if (max < p)
        max = p;
    }
  }
  cout << max << endl;
  return 0;
}
void input(vector<int> &fx, int &n, int &max) {
  int m;
  m = -1;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> fx[i];
    if (fx[i] == m) {
      max = 0;
      n--;
      i--;
    } else
      m = fx[i];
  }
  return;
}

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void input(vector<int> &, int &, int &);
int main() {
  vector<int> fx(200001);
  int dec = 0, n, at1, at2, n_max, n_min;
  int ans, p, max, min;
  ans = -1000000001;
  max = -1000000001;
  input(fx, n, max);
  min = fx[0];
  for (int i = 1; i < n; ++i) {
    p = fx[i] - min;
    if (max < p)
      max = p;
    if (min > fx[i])
      min = fx[i];
  }
  cout << max << endl;
  return 0;
}
void input(vector<int> &fx, int &n, int &max) {
  int m;
  m = -1;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> fx[i];
    if (fx[i] == m) {
      max = 0;
      n--;
      i--;
    } else
      m = fx[i];
  }
  return;
}