#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define N 200000

int main() {
  lli ans, n;
  lli a[N];

  cin >> n;

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

  ans = a[1] - a[0];
  for (lli i = 0; i < n - 1; i++) {
    for (lli j = i + 1; j < n; j++) {
      if (ans < a[j] - a[i]) {
        ans = a[j] - a[i];
      }
    }
  }

  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define N 200000

int main() {
  lli ans, n, mini;
  lli a[N];

  cin >> n;

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

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

  cout << ans << endl;
  return 0;
}


#include <climits>
#include <iostream>
#include <math.h>
#include <vector>

int caluculate(const std::vector<int> &ls) {
  int max = INT_MIN, diff = 0;

  for (int i = 1; i < ls.size(); i++) {
    for (int j = i; j < ls.size(); j++) {
      diff = ls.at(j) - ls.at(i - 1);
      max = (std::max)(max, diff);
    }
    // std::cout<<ls.at(i)<<std::endl;
  }
  return max;
}

int main() {
  int n, x, maxValue;
  std::vector<int> ls(0);

  std::cin >> n;
  while (n--) {
    std::cin >> x;
    ls.push_back(x);
  }
  //?????§??????????¨????
  maxValue = caluculate(ls);

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

#include <climits>
#include <iostream>
#include <math.h>
#include <vector>

int caluculate(const std::vector<int> &ls) {
  int max = INT_MIN, min = ls.at(0), diff = 0;

  // for(int j=1;i<ls.size();j++){
  //     for(int i=0;i<j-1;i++){
  //         diff=ls.at(j)-ls.at(i);
  //         max=(std::max)(max,diff);
  //     }
  //     //std::cout<<ls.at(i)<<std::endl;
  // }
  for (int j = 1; j < ls.size(); j++) {
    max = (std::max)(max, ls.at(j) - min);
    min = (std::min)(min, ls.at(j));
  }
  return max;
}

int main() {
  int n, x, maxValue;
  std::vector<int> ls(0);

  std::cin >> n;
  while (n--) {
    std::cin >> x;
    ls.push_back(x);
  }
  //?????§??????????¨????
  maxValue = caluculate(ls);

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


#include <stdio.h>
static const int MAX = 200000;

int main() {

  int n, i, j;
  int r, rmax;

  scanf("%d", &n);

  int R[MAX];

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

  rmax = -1000000000;

  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (j > i) {
        r = R[j] - R[i];
        if (r > rmax)
          rmax = r;
      }
    }
  }

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

  return 0;
}

#include <stdio.h>

int main() {

  int n, i, j;
  int r, rmax, rmin;

  scanf("%d", &n);

  int R[200000];

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

  rmax = -1000000000;
  rmin = R[0];

  for (i = 1; i < n; i++) {
    int x;
    x = R[i] - rmin;
    if (x > rmax)
      rmax = x;

    if (rmin > R[i])
      rmin = R[i];
  }

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

  return 0;
}


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

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


#include <algorithm>
#include <cstdio>

using namespace std;

const int MAX_VALUE = 200000;
int R[MAX_VALUE];

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

  int max_income = -1000000001;
  for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++)
      max_income = max(max_income, R[j] - R[i]);

  printf("%d\\n", max_income);
}

#include <algorithm>
#include <cstdio>

using namespace std;

const int MAX_VALUE = 200000;
int R[MAX_VALUE];

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

  int min_val = R[0];
  int max_val = -1000000001;
  for (int j = 1; j < n; j++) {
    max_val = max(max_val, R[j] - min_val);
    min_val = min(min_val, R[j]);
  }
  printf("%d\\n", max_val);
}


#include <algorithm>
#include <iostream>

using namespace std;

int n;
const int MAX_N = 200000;
int R[MAX_N];

int main() {

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

#include <algorithm>
#include <iostream>

using namespace std;

int n;
const int MAX_N = 200000;
int R[MAX_N];

int main() {

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> R[i];
  }
  int maxv = -2000000000;
  int 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 <bits/stdc++.h>
using namespace std;
int main() {
  int r[200001];
  int n;
  cin >> n;
  int max = -1000000001;
  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 (max < (r[j] - r[i])) {
        max = r[j] - r[i];
      }
    }
  }
  cout << max << endl;

  return 0;
}

#include <bits/stdc++.h>
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>
#include <limits.h>
using namespace std;

int main(void) {
  int N, *A, dif, max;

  cin >> N;

  A = new int[N];

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

    if (i == 1) {
      max = A[i] - A[i - 1];
    } else if (i > 0) {
      for (int j = i - 1; j > -1; j--) {
        dif = A[i] - A[j];
        if (dif > max)
          max = dif;
      }
    }
  }

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

  return 0;
}

#include <iostream>
#include <limits.h>
using namespace std;

int main(void) {
  int N, *A, dif, max, minID, maxID;

  cin >> N;

  A = new int[N];
  maxID = 1;
  minID = 0;

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

  max = A[maxID] - A[minID];
  if (A[maxID] < A[minID]) {
    minID = 1;
  }

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

    if (minID > maxID || A[maxID] < A[i]) {
      maxID = i;
      if (max < A[maxID] - A[minID] && maxID > minID)
        max = A[maxID] - A[minID];
    }
    if (A[minID] > A[i]) {
      minID = i;
    }
  }

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

  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;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (maxv < R[j] - R[i]) {
        maxv = R[j] - 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 j = 1; j < n; j++) {
    if (maxv < R[j] - minv) {
      maxv = R[j] - minv;
    }
    if (minv > R[j]) {
      minv = R[j];
    }
  }
  cout << maxv << endl;
  return 0;
}


#include <iostream>

using namespace std;

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

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

  return 0;
}

#include <iostream>

using namespace std;

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

  int R[n];
  for (int i = 0; i < n; i++) {
    cin >> R[i];
  }
  int max_R = 1;
  int max_val = 1 - 1e9;

  for (int i = n - 2; i >= 0; i--) {
    if (R[i + 1] > max_R)
      max_R = R[i + 1];
    int val = max_R - R[i];
    if (val > max_val)
      max_val = val;
  }

  cout << max_val << endl;

  return 0;
}


#include <iostream>

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n, max = -1000000000, x;
  std::cin >> n;
  int rt[n];
  for (int i = 0; i < n; i++) {
    std::cin >> rt[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      x = rt[j] - rt[i];
      if (max < x) {
        max = x;
      }
    }
  }
  std::cout << max << '\\n';
}

#include <algorithm>
#include <iostream>

int main() {
  int n, maxv = -2000000000, minv;
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  std::cin >> n;
  int rt[n];
  for (int i = 0; i < n; ++i) {
    std::cin >> rt[i];
  }
  minv = rt[0];
  for (int i = 1; i < n; ++i) {
    maxv = std::max(maxv, rt[i] - minv);
    minv = std::min(minv, rt[i]);
  }
  std::cout << maxv << '\\n';
}


#include <cstdio>
using namespace std;
int main(void) {
  int n;
  long r[200000], maxv;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &r[i]);
  }
  maxv = r[1] - r[0];
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (maxv < r[i] - r[j])
        maxv = r[i] - r[j];
    }
  }
  printf("%d\\n", maxv);
  return 0;
}

#include <cstdio>
using namespace std;
int main(void) {
  int n;
  long long r[200000], maxv, minv;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%ld", &r[i]);
  }
  maxv = r[1] - r[0];
  minv = r[0];
  for (int i = 1; i < n; i++) {
    if (minv > r[i - 1])
      minv = r[i - 1];
    if (maxv < r[i] - minv)
      maxv = r[i] - minv;
  }
  printf("%d\\n", maxv);
  return 0;
}


// #include "stdafx.h"
#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 max = -999999999;
  for (int i = 0; i < N - 1; 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;
}

// include "stdafx.h"
#include <algorithm>
#include <iostream>
using namespace std;
void maximumProfit();

int main() {
  maximumProfit();
  return 0;
}

void maximumProfit() {
  const int MAX = 200000;
  int R[MAX];
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> R[i];
  }
  int mi = R[0];
  int ma = -2000000000;
  for (int i = 1; i < N; i++) {
    ma = max(ma, R[i] - mi);
    mi = min(mi, R[i]);
  }

  cout << ma << endl;
}


#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int *r = new int[n];
  for (int i = 0; i < n; i++)
    cin >> r[i];
  int max = r[1] - r[0];

  for (int i = 0; i < n - 1; i++)
    for (int j = n - 1 - i; j > 0; j--)
      max = (max < r[i + j] - r[i]) ? r[i + j] - r[i] : max;

  cout << max << endl;
}

#include <iostream>
using namespace std;

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

  int min = r[0], maxv = r[1] - r[0];

  for (int i = 1; i < n; i++) {
    maxv = (maxv < r[i] - min) ? r[i] - min : maxv;
    min = (min > r[i]) ? r[i] : min;
  }
  cout << maxv << endl;
}


#include <iostream>
using namespace std;

string list[32];
int res = 0;
int sa[1000];

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

#include <iostream>
using namespace std;

string list[32];
int res = 0;
int sa[1000];

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


#include <iostream>
using namespace std;
int R[2000];
int num;
int main() {
  // cout << "????????\\???????????¶??´??????" << endl;
  cin >> num;
  for (int i = 0; i < num; i++) {
    cin >> R[i];
  }
  int maxv = -2000000000;
  int minv = R[0];
  for (int j = 1; j < num; j++) {
    if (maxv < R[j] - minv) {
      maxv = R[j] - minv;
    }
    if (minv > R[j]) {
      minv = R[j];
    }
    /*	for (int i = 0; i < j; i++)
            {
                    if (maxv < R[j] - R[i])
                    {
                            maxv = R[j] - R[i];
                    }
            }*/
  }
  cout << maxv << endl;
  return 0;
}

#include <iostream>
using namespace std;
int R[200000];
int num;
int main() {
  // cout << "????????\\???????????¶??´??????" << endl;
  cin >> num;
  for (int i = 0; i < num; i++) {
    cin >> R[i];
  }
  int maxv = -2000000000;
  int minv = R[0];
  for (int j = 1; j < num; j++) {
    if (maxv < R[j] - minv) {
      maxv = R[j] - minv;
    }
    if (minv > R[j]) {
      minv = R[j];
    }
    /*	for (int i = 0; i < j; i++)
            {
                    if (maxv < R[j] - R[i])
                    {
                            maxv = R[j] - R[i];
                    }
            }*/
  }
  cout << maxv << endl;
  return 0;
}


#include <algorithm>
#include <iostream>

int main() {
  using namespace std;
  const int MAX = 20000000;
  int R[MAX], n;

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

  int maxv = -1000;
  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>

int main() {
  using namespace std;
  const int MAX = 200000;
  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;
#include <algorithm>

int main(void) {

  int n;
  cin >> n;

  int price[200000];
  int maxi;

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

  maxi = price[1] - price[0];

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

  cout << maxi << endl;
}

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

int main(void) {

  int n;
  cin >> n;

  int price[200000];
  int maxi;
  int mini;

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

  mini = price[0];
  maxi = price[1] - mini;

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

    maxi = max(maxi, price[i] - mini);
    if (mini > price[i])
      mini = price[i];
  }

  cout << maxi << endl;
}


#include <cstdio>
#define MAX 200000
#define MIN -999999999

int main() {
  int n;
  scanf("%d", &n);

  int profit[MAX];
  for (int i = 0; i < n; i++)
    scanf("%d", &profit[i]);

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

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

  return 0;
}

#include <cstdio>
#define MAX 200000
#define MIN -999999999

int maximumProfit(int *profit, int n);

int main() {
  int n;
  scanf("%d", &n);

  int profit[MAX];
  for (int i = 0; i < n; i++)
    scanf("%d", &profit[i]);

  int max = maximumProfit(profit, n);

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

  return 0;
}

int maximumProfit(int *profit, int n) {
  int max = MIN, min = profit[0];
  for (int i = 1; i < n; i++) {
    max = max > profit[i] - min ? max : profit[i] - min;
    min = min < profit[i] ? min : profit[i];
  }
  return max;
}


#include <iostream>
using namespace std;
int main(void) {
  int n, r[200000], m;
  cin >> n >> r[0] >> r[1];
  m = r[1] - r[0];
  for (int i = 2; i < n; i++)
    cin >> r[i];
  for (int j = 2; j < n; j++) {
    for (int i = 0; i < j; i++) {
      if (r[j] - r[i] > m)
        m = r[j] - r[i];
    }
  }
  cout << m << endl;
  return 0;
}

#include <iostream>
using namespace std;
int main(void) {
  int n, m, r, ans = -1000000001;
  cin >> n;
  cin >> m;
  for (int i = 1; i < n; i++) {
    cin >> r;
    ans = max(ans, r - m);
    m = min(m, r);
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <string.h>
using namespace std;
long a[200001];
int main() {
  long n;
  int i, j;
  long max;
  memset(a, 0, sizeof(a));
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  max = a[1] - a[0];
  for (i = 0; i < n; i++) {
    for (j = n - 1; j > i; j--) {
      if (max < a[j] - a[i]) {
        max = a[j] - a[i];
      }
    }
  }
  cout << max << endl;
  return 0;
}

#include <iostream>
#include <string.h>
using namespace std;
long a[200001];
int main() {
  int n;
  int i, j;
  int max;
  int small;
  memset(a, 0, sizeof(a));
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  max = a[1] - a[0];
  small = a[0];
  for (i = 1; i < n; i++) {
    if (max < a[i] - small) {
      max = a[i] - small;
    }
    if (small > a[i]) {
      small = a[i];
    }
  }
  cout << max << endl;
  return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
int main(int const argc, char const **argv) {
  int n;
  std::cin >> n;
  std::vector<int> vec(n);
  for (int i = 0; i < n; ++i) {
    // std::cin >> vec[i];
    scanf("%d\\n", &vec[i]);
  }

  int max = -2147483648;
  int r;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      r = vec[j] - vec[i];
      if (max < r) {
        max = r;
      }
    }
  }
  std::cout << max << std::endl;
}

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
int main(int const argc, char const **argv) {
  int n;
  std::cin >> n;
  std::vector<int> vec(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> vec[i];
    // scanf("%d\\n", & vec[i]);
  }
  int min = vec[0];
  int max = -2147483647;
  for (int i = 1; i < n; ++i) {
    max = std::max(max, vec[i] - min);
    min = std::min(min, vec[i]);
  }
  std::cout << max << std::endl;
}


#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

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

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

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

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

  cout << profit << endl;

  return 0;
}

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

// #define TEST

using namespace std;

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

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

  int profit = r[1] - r[0];
  int r_min = r[0];

#ifdef TEST
  cout << "default : "
       << "r_min = " << r_min << " : "
       << "profit = " << profit << " : \\n";
#endif

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

#ifdef TEST
    cout << "i = " << i << " : ";
#endif

    if (profit < r[i] - r_min) {
      profit = r[i] - r_min;

#ifdef TEST
      cout << "profit = " << profit << " : ";
#endif
    }

    if (r_min > r[i]) {
      r_min = r[i];
#ifdef TEST
      cout << "r_min = " << r_min << " : ";
#endif
    }
#ifdef TEST
    cout << endl;
#endif
  }

#ifdef TEST
  cout << "ans = ";
#endif
  cout << profit << endl;

  return 0;
}


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

int timeSerialDiff(vector<int> &v) {
  int size = v.size(), i, j, max, cnt = 0;
  for (i = 0; i < size; i++) {
    int start = v[i];
    for (j = i + 1; j < size; j++) {
      int diff = v[j] - v[i];
      max = (cnt == 0 || max < diff) ? diff : max;
      cnt++;
    }
  }
  return max;
}
int main() {
  int n, i, x, min, max;
  vector<int> v;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  cout << timeSerialDiff(v) << endl;
  return 0;
}

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

int timeSerialDiff(vector<int> &v) {
  int size = v.size();
  if (size < 2) {
    return 0;
  }
  int i, max, min, cnt = 0;
  min = v[0];
  max = v[1] - v[0];
  for (i = 1; i < size; i++) {
    int diff = v[i] - min;
    max = max < diff ? diff : max;
    min = min > v[i] ? v[i] : min;
  }
  return max;
}
int main() {
  int n, i, x, min, max;
  vector<int> v;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  cout << timeSerialDiff(v) << endl;
  return 0;
}


// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  // A??????????´???????
  int max = A[1] - A[0];
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (max < A[j] - A[i])
        max = A[j] - A[i];
    }
  }
  cout << max << endl;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D
#include <iostream>
using namespace std;

int max(int x, int y) {
  if (x > y)
    return x;
  else
    return y;
}

int min(int x, int y) {
  if (x > y)
    return y;
  else
    return x;
}

int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  // A??????????´???????
  int maxv = A[1] - A[0];
  int minv = A[0];

  for (int i = 1; i < N; i++) {
    maxv = max(maxv, A[i] - minv);
    minv = min(minv, A[i]);
    //  cout << minv << " " << maxv << endl;
  }
  cout << maxv << endl;
}


#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 max = R[1] - R[0];
  int c = max;

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

#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 max = R[1] - R[0];
  int c = max;
  int min = R[0] < R[1] ? R[0] : R[1];

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


#include <iostream>
#include <limits>
#include <math.h>
using namespace std;

int main() {
  int n;
  int offset = numeric_limits<int>::min();
  cin >> n;
  int array[n];
  for (int i = 0; i < n; i++) {
    cin >> array[i];
    if (i >= 1) {
      for (int j = i - 1; j >= 0; j--) {
        if (offset < array[i] - array[j])
          offset = array[i] - array[j];
      }
    }
  }

  cout << offset << endl;

  return 0;
}

#include <iostream>
#include <limits>
#include <math.h>
using namespace std;

int main() {
  int n, min, max, offset;
  //	int offset = numeric_limits<int>::min();
  cin >> n;
  //	int array[n];
  cin >> min;
  cin >> max;
  offset = max - min;
  if (min > max)
    min = max;
  for (int i = 0; i < n - 2; i++) {
    int temp, tempoff;
    cin >> temp;
    if (min > temp) {
      min = temp;

    } else {
      tempoff = temp - min;
      if (offset < tempoff)
        offset = tempoff;
    }
  }

  //		if(i>=1)
  //		{
  //			for(int j = i-1; j>=0; j--) {
  //				if(offset<array[i]-array[j])
  //				offset = array[i]-array[j];
  //			}
  //		}
  //	}

  cout << offset << endl;

  return 0;
}


#include <iostream>

using namespace std;

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

  int *R = new int[n];

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

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

  cout << maxv << endl;

  delete[] R;
}

#include <iostream>

using namespace std;

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

  int *R = new int[n];

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

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

  cout << maxv << endl;

  delete[] R;
}


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

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


#include <iostream>
#include <vector>

int main() {
  std::vector<long> Dat = {};
  int t = 0;
  std::cin >> t;
  for (int i = 0; i < t; i++) {
    int tmp = 0;
    std::cin >> tmp;
    Dat.push_back(tmp);
  }
  long max = *(Dat.begin() + 1) - *Dat.begin();
  for (auto cur = Dat.begin(); cur != Dat.end() - 1; cur++) // may bug
  {
    long start = *cur;
    long tmp = *(cur + 1);
    for (auto curr = cur + 2; curr != Dat.end(); curr++) {
      if (*curr > tmp)
        tmp = *curr;
    }
    if (tmp - *cur > max)
      max = tmp - *cur;
  }
  std::cout << max << std::endl;
  return 0;
}

#include <iostream>
#include <vector>

int main() {
  std::vector<long> Dat = {};
  int t = 0;
  std::cin >> t;
  for (int i = 0; i < t; i++) {
    int tmp = 0;
    std::cin >> tmp;
    Dat.push_back(tmp);
  }
  long min = *Dat.begin(), max = -2E9;
  for (auto cur = Dat.begin() + 1; cur != Dat.end(); cur++) {
    if (*(cur - 1) < min)
      min = *(cur - 1);
    if (*cur - min > max)
      max = *cur - min;
  }
  std::cout << max << std::endl;
  return 0;
}


#define FOR(i, min, max) for (int(i) = (min); (i) < (max); (i)++)

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n, ans, v[200000], pre;
  cin >> n;
  FOR(i, 0, n) { cin >> v[i]; }
  ans = v[1] - v[0];
  pre = 0;

  FOR(i, 0, n) {
    if (pre != 0 || v[i] <= v[pre])
      FOR(j, i + 1, n) {
        if (v[j] - v[i] > ans) {
          ans = v[j] - v[i];
          pre = i;
        }
      }
  }
  cout << ans << endl;
  return 0;
}

#define FOR(i, min, max) for (int(i) = (min); (i) < (max); (i)++)

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n, ans, v[200000], pre = 0, pro = 0;
  cin >> n;
  FOR(i, 0, n) { cin >> v[i]; }
  ans = v[1] - v[0];

  FOR(i, 0, n) {
    if (v[i] <= v[pre])
      if (pro <= i) {
        FOR(j, i + 1, n) {
          if (v[j] - v[i] > ans) {
            ans = v[j] - v[i];
            pre = i;
            pro = j;
          }
        }
      } else {
        ans = v[pro] - v[i];
        pre = i;
      }
  }
  cout << ans << endl;
  return 0;
}


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

#include <iostream>
using namespace std;
int main() {
  int num;
  cin >> num;
  int currency[num];
  cin >> currency[0] >> currency[1];
  int min = (currency[0] < currency[1] ? currency[0] : currency[1]);
  int tmp = currency[1] - currency[0];
  for (int i = 2; i < num; i++) {
    cin >> currency[i];
    if (currency[i] - min > tmp)
      tmp = currency[i] - min;
    if (currency[i] < min)
      min = currency[i];
  }
  cout << tmp << endl;
  return 0;
}


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

using namespace std;

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

  int r[n];

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

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

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

  cout << max_diff << endl;

  return 0;
}

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

using namespace std;

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

  int r[n];

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

  int _max = r[1] - r[0];
  int _min = pow(10, 9);

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

  cout << _max << endl;

  return 0;
}


#include <cmath>
#include <iostream>
#include <list>
#include <utility>
#include <vector>
using namespace std;

#define D

#ifdef D
int main(void) {
  int n;
  cin >> n;
  vector<long long> arr(n);
  for (auto &a : arr) {
    cin >> a;
  }
  long long max = arr.back() - arr.front();
  long long dis;
  for (size_t i = 0; i < n; i++) {
    for (size_t j = i + 1; j < n; j++) {
      dis = arr[j] - arr[i];
      if (max < dis)
        max = dis;
    }
  }
  cout << max << endl;

  return 0;
}
#endif // D

#include <cmath>
#include <iostream>
#include <list>
#include <utility>
#include <vector>
using namespace std;

#define D

#ifdef D

int main(void) {
  int n;
  cin >> n;
  int max = -1000000000;

  int dis, in;
  cin >> in;
  int min = in;

  for (size_t i = 1; i < n; i++) {
    cin >> in;

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

  cout << max << endl;

  return 0;
}
#endif // D


#include <iostream>

using namespace std;
#define NUMBER 200000

int main() {

  int ary[NUMBER];

  for (int i = 0; i < NUMBER; i++) {
    ary[i] = -1;
  }

  int n;
  cin >> n;

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

  int max = -10000000000;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i - 1; j >= 0; j--) {
      if (max < ary[i] - ary[j]) {
        max = ary[i] - ary[j];
      }
    }
  }
  cout << max << endl;
}

#include <iostream>

using namespace std;
#define NUMBER 200000

int main() {

  int ary[NUMBER];
  int min_register[NUMBER];

  /*
  for(int i = 0; i < NUMBER; i++){
          ary[i] = -1;
          min_register[i] = -1;
  }
  */

  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> ary[i];
  }
  int min = ary[0];
  min_register[0] = min;
  for (int i = 1; i < n; i++) {
    if (min > ary[i]) {
      min = ary[i];
    }
    min_register[i] = min;
  }

  int max = -1000000001;
  for (int i = n - 1; i > 0; i--) {
    max = (max > ary[i] - min_register[i - 1]) ? max
                                               : ary[i] - min_register[i - 1];
  }
  cout << max << endl;
}


#include <iostream>
#include <limits>
#include <vector>

using namespace std;

int solve(const vector<int> &v) {
  int res = numeric_limits<int>::min();
  for (int i = 0; i < v.size(); i++) {
    for (int j = i + 1; j < v.size(); j++) {
      res = max(res, v[j] - v[i]);
    }
  }
  return res;
}

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

  vector<int> v;
  for (int i = 0; i < n; i++) {
    int val;
    cin >> val;
    v.push_back(val);
  }

  cout << solve(v) << endl;

  return 0;
}

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

using namespace std;

int solve(const vector<int> &v) {
  int res = numeric_limits<int>::min();
  for (int i = 0; i < v.size(); i++) {
    for (int j = i + 1; j < v.size(); j++) {
      res = max(res, v[j] - v[i]);
    }
  }
  return res;
}

int solve2(const vector<int> &v) {
  int maxv = numeric_limits<int>::min();
  int minv = v.front();

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

  return maxv;
}

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

  vector<int> v;
  for (int i = 0; i < n; i++) {
    int val;
    cin >> val;
    v.push_back(val);
  }

  // cout << solve(v) << endl;
  cout << solve2(v) << endl;

  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n, r[1000000000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }
  int mi = r[0], ma = r[0];
  for (int j = 1; j < n; j++) {
    if (ma < r[j] - mi)
      ma = r[j] - mi;
    if (mi > r[j])
      mi = r[j];
  }
  cout << ma - mi << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int n, a[200010], ma[200010], mi[200010], ans = -1145141919;
int main() {
  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) {
    if (i == 0)
      mi[i] = a[i];
    else
      mi[i] = min(mi[i - 1], a[i]);
  }
  for (int i = n - 1; i >= 0; i--) {
    if (i == n - 1)
      ma[i] = a[i];
    else
      ma[i] = max(ma[i + 1], a[i]);
  }
  rep(i, n - 1) ans = max(ma[i + 1] - mi[i], ans);
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long> nums;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    nums.push_back(x);
  }

  long max = -1000000000;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      long diff = nums[j] - nums[i];
      if (diff > max) {
        max = diff;
      }
    }
  }
  cout << max << endl;
}

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long> nums;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    nums.push_back(x);
  }

  long del_max = nums[1] - nums[0];
  long minv = nums[0];
  for (int j = 1; j < n; ++j) {
    long delta = nums[j] - minv;
    if (delta > del_max) {
      del_max = delta;
    }
    if (minv > nums[j]) {
      minv = nums[j];
    }
  }
  cout << del_max << endl;
}


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

int main() {
  int n, r[200100], max = -2000000000;
  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 <bits/stdc++.h>
using namespace std;

int main() {
  int n, r[200100], maxv = -1000000000;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }
  int minv = r[0];
  for (int j = 1; j < n; j++) {
    if (r[j] - minv > maxv)
      maxv = r[j] - minv;
    if (r[j] < minv)
      minv = r[j];
  }
  cout << maxv << endl;
  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int A[200000] = {0}, n;
  cin >> n;

  int i, j;

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

      if (A[j] - A[i] > max) {
        max = A[j] - A[i];
      }
    }
  cout << max << endl;
  return 0;
}

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

int main() {
  int A[200000], n;
  cin >> n;

  int i, j;

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


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

using namespace std;
int getMaxProfit(int *ary, int ary_size);

int main() {
  string str;
  getline(cin, str);
  int num;
  stringstream num_ss(str);
  num_ss >> num;

  int counter = 0;
  int *ary = new int[num];
  for (int i = 0; i < num; i++) {
    getline(cin, str);
    stringstream tmp_ss(str);
    tmp_ss >> ary[i];
  }

  cout << getMaxProfit(ary, num) << endl;
  return 0;
}

int getMaxProfit(int *ary, int ary_size) {
  int max_prf = ary[1] - ary[0];
  for (int i = 2; i < ary_size; i++) {
    for (int j = 0; j < i; j++) {
      int tmp = ary[i] - ary[j];
      if (tmp > max_prf) {
        max_prf = tmp;
      }
    }
  }
  return max_prf;
}

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

using namespace std;
int getMaxProfit(int *ary, int ary_size);

int main() {
  string str;
  getline(cin, str);
  int num;
  stringstream num_ss(str);
  num_ss >> num;

  int counter = 0;
  int *ary = new int[num];
  for (int i = 0; i < num; i++) {
    getline(cin, str);
    stringstream tmp_ss(str);
    tmp_ss >> ary[i];
  }

  cout << getMaxProfit(ary, num) << endl;
  return 0;
}

int getMaxProfit(int *ary, int ary_size) {
  int max_prf = ary[1] - ary[0];
  int min_num = (ary[1] > ary[0] ? ary[0] : ary[1]);
  for (int i = 2; i < ary_size; i++) {
    int tmp = ary[i] - min_num;
    if (tmp > max_prf) {
      max_prf = tmp;
    }
    min_num = (ary[i] < min_num ? ary[i] : min_num);
  }
  return max_prf;
}


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

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

/*int main(){
        int n;
        cin>>n;
        int a[n];
        for(int i = 0;i<n;i++){
                cin>>a[i];
        }
        int syueki = a[1] -a[0];
        for(int i = 0;i<n-1;i++){
                for(int j = i+1;j<n;j++){
                        syueki = max(syueki,a[j]-a[i]);
                }
        }
        cout<<syueki<<endl;
}*/


#include <iostream>
using namespace std;

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

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

int main() {
  int n;
  cin >> n;
  int maxv = -1000000000;
  int minv;
  int R[200000];
  for (int t = 0; t < n; t++) {
    cin >> R[t];
  }
  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 <bits/stdc++.h>
using namespace std;

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

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

  cout << maxval << endl;

  return 0;
}

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

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

  int maxval = -1000000000;
  int minval = a[0];
  for (int i = 1; i < n; i++) {
    maxval = max(maxval, a[i] - minval);
    minval = min(minval, a[i]);
  }

  cout << maxval << endl;

  return 0;
}


#define pb push_back
#define vi vector<int>
#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  vi pro(n, 0);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> pro[i];
  int ans = 0, min_ = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, pro[i] - pro[min_]);
    if (pro[min_] > pro[i])
      min_ = i;
  }
  cout << ans << endl;
}
int main(void) {
  solve();
  return 0;
}

#define pb push_back
#define vi vector<int>
#include <bits/stdc++.h>
using namespace std;
int pro[300000];
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> pro[i];
  int ans = INT_MIN, min_ = 0;
  for (int i = 1; i < n; i++) {
    ans = max(ans, pro[i] - pro[min_]);
    if (pro[min_] > pro[i])
      min_ = i;
  }
  //	if(ans == 0) ans = -1;
  cout << ans << endl;
}
int main(void) {
  solve();
  return 0;
}

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


//
// Created by sanyinchen on 17/4/17.
//

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

using namespace std;

vector<int> findMaxWithMidPoint(int *array, int low, int high) {

  int mid = (low + high) / 2;
  int leftSum = 0, leftLow = mid;
  int rightSum = 0, rightHigh = mid + 1;
  int maxLeft = array[leftLow], maxRight = array[rightHigh];

  vector<int> res;
  for (int i = mid; i >= low; i--) {
    leftSum += array[i];
    if (leftSum > maxLeft) {
      maxLeft = leftSum;
      leftLow = i;
    }
  }
  res.push_back(leftLow);

  for (int i = mid + 1; i <= high; i++) {
    rightSum += array[i];
    if (rightSum > maxRight) {
      maxRight = rightSum;
      rightHigh = i;
    }
  }
  res.push_back(rightHigh);
  //    cout << low << " " << high << endl;
  //    cout << "sum:" << maxLeft + maxRight << " left:" << leftLow << " " <<
  //    "high:" << rightHigh << endl;
  res.push_back(maxLeft + maxRight);

  return res;
}

vector<int> findMax(int *array, int low, int high) {

  if (low == high) {

    vector<int> res;
    res.push_back(low);
    res.push_back(high);
    res.push_back(array[low]);
    return res;
  } else {
    int mid = (low + high) / 2;

    vector<int> left = findMax(array, low, mid);
    vector<int> right = findMax(array, mid + 1, high);
    vector<int> midRes = findMaxWithMidPoint(array, low, high);
    //        cout << "left:" << left[0] << " " << left[1] << " " << left[2] <<
    //        endl; cout << "right:" << right[0] << " " << right[1] << " " <<
    //        right[2] << endl; cout << "midRes:" << midRes[0] << " " <<
    //        midRes[1] << " " << midRes[2] << endl;

    if (left[2] >= right[2] && left[2] >= midRes[2]) {
      return left;
    }
    if (right[2] >= left[2] && right[2] >= midRes[2]) {

      return right;
    }

    return midRes;
  }
}

int main() {
  freopen("../files/in.txt", "r", stdin);
  int input[200001] = {0};
  int data[200001] = {0};
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> input[i];
    if (i == 0) {
      data[i] = 0 - input[i];
    } else {
      data[i] = input[i] - input[i - 1];
    }
  }
  //    for (int i = 0; i < n; i++) {
  //        cout << data[i] << " ";
  //    }
  // cout << endl;
  vector<int> res = findMax(data, 0, n - 1);
  // cout << res[0] << " " << res[1] << " " << res[2] << endl;
  cout << res[2] << endl;

  return 0;
}

//
// Created by sanyinchen on 17/4/17.
//

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

using namespace std;

vector<int> findMaxWithMidPoint(int *array, int low, int high) {

  int mid = (low + high) / 2;
  int leftSum = 0, leftLow = mid;
  int rightSum = 0, rightHigh = mid + 1;
  int maxLeft = array[leftLow], maxRight = array[rightHigh];

  vector<int> res;
  for (int i = mid; i >= low; i--) {
    leftSum += array[i];
    if (leftSum > maxLeft) {
      maxLeft = leftSum;
      leftLow = i;
    }
  }
  res.push_back(leftLow);

  for (int i = mid + 1; i <= high; i++) {
    rightSum += array[i];
    if (rightSum > maxRight) {
      maxRight = rightSum;
      rightHigh = i;
    }
  }
  res.push_back(rightHigh);
  //    cout << low << " " << high << endl;
  //    cout << "sum:" << maxLeft + maxRight << " left:" << leftLow << " " <<
  //    "high:" << rightHigh << endl;
  res.push_back(maxLeft + maxRight);

  return res;
}

vector<int> findMax(int *array, int low, int high) {

  if (low == high) {

    vector<int> res;
    res.push_back(low);
    res.push_back(high);
    res.push_back(array[low]);
    return res;
  } else {
    int mid = (low + high) / 2;

    vector<int> left = findMax(array, low, mid);
    vector<int> right = findMax(array, mid + 1, high);
    vector<int> midRes = findMaxWithMidPoint(array, low, high);
    //        cout << "left:" << left[0] << " " << left[1] << " " << left[2] <<
    //        endl; cout << "right:" << right[0] << " " << right[1] << " " <<
    //        right[2] << endl; cout << "midRes:" << midRes[0] << " " <<
    //        midRes[1] << " " << midRes[2] << endl;

    if (left[2] >= right[2] && left[2] >= midRes[2]) {
      return left;
    }
    if (right[2] >= left[2] && right[2] >= midRes[2]) {

      return right;
    }

    return midRes;
  }
}

int main() {
  // freopen("../files/in.txt", "r", stdin);
  int input[200001] = {0};
  int data[200001] = {0};
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> input[i];
    if (i == 0) {
      data[i] = 0 - input[i];
    } else {
      data[i] = input[i] - input[i - 1];
    }
  }
  //    for (int i = 0; i < n; i++) {
  //        cout << data[i] << " ";
  //    }
  // cout << endl;
  vector<int> res = findMax(data, 0, n - 1);
  // cout << res[0] << " " << res[1] << " " << res[2] << endl;
  cout << res[2] << endl;

  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;
#define MAX 200000

int main() {

  int n;
  cin >> n;
  int A[MAX];

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

  int maxv = A[1] - A[0];

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

  cout << maxv << endl;

  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
#define MAX 200000

int main() {

  int n;
  cin >> n;
  int A[MAX];

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

  int maxv = A[1] - A[0];
  int minv = A[0];

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

  cout << maxv << endl;

  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n, max, tmp;
  cin >> n;
  int input[n];
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    input[i] = tmp;
  }

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

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

#include <iostream>
using namespace std;

int main() {
  int n, max, tmp, minR;
  cin >> n;
  int input[n];
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    input[i] = tmp;
  }

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

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


#include <iostream>
using namespace std;
int main() {

  int n, x[1000000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  int max = x[1] - x[0];
  for (int k = 0; k < n; k++) {
    for (int m = k + 1; m < n; m++) {
      if (max < (x[m] - x[k]))
        max = x[m] - x[k];
    }
  }
  cout << max << endl;
}

#include <iostream>
using namespace std;
int main() {

  int n, x[1000000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  int max = x[1] - x[0];
  int min = x[0];
  for (int k = 1; k < n; k++) {
    if (max < (x[k] - min))
      max = (x[k] - min);
    if (min > x[k])
      min = x[k];
  }
  cout << max << endl;
}


#include <cstdio>

#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 <climits>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int R[n];
  for (int t = 0; t < n; t++) {
    scanf("%d", &R[t]);
  }
  int minv = R[0];
  int maxv = -INT_MAX;
  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 <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define SORT(c) sort((c).begin(), (c).end())
const double EPS = 1e-10;                 // sample:if((double)>=(double)+EPS)
#define CLR(a) memset((&a), 0, sizeof(a)) // clear memory
#define dump(x) cerr << #x << " = " << (x) << endl; // debug
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
// cin,cout release
// std::cin.tie(0);
// ios::sync_with_stdio(false);

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

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define SORT(c) sort((c).begin(), (c).end())
const double EPS = 1e-10;                 // sample:if((double)>=(double)+EPS)
#define CLR(a) memset((&a), 0, sizeof(a)) // clear memory
#define dump(x) cerr << #x << " = " << (x) << endl; // debug
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
// cin,cout release
// std::cin.tie(0);
// ios::sync_with_stdio(false);

int main(void) {
  int n;
  cin >> n;
  // vector<int> r;
  int r[200000];
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }
  int maxv = INT_MIN, 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>
#include <vector>
using namespace std;

int main() {
  vector<int> nums;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int l;
    cin >> l;
    nums.push_back(l);
  }
  int min = nums[0];
  vector<int> candidits;
  for (int i = 1; i < n; ++i) {
    if (min > nums[i]) {
      min = nums[i];
      int max = *max_element(nums.begin() + i + 1, nums.end());
      candidits.push_back(max - min);
    }
  }
  int max = *max_element(candidits.begin(), candidits.end());
  cout << max << endl;
  return 0;
}

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

int main() {
  vector<int> nums;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int l;
    cin >> l;
    nums.push_back(l);
  }
  vector<int> candidits;
  int min = -1;
  for (int i = 0; i < n - 1; ++i) {
    if (min == -1 || min > nums[i]) {
      min = nums[i];
      int max = *max_element(nums.begin() + i + 1, nums.end());
      candidits.push_back(max - min);
    }
  }
  int max = *max_element(candidits.begin(), candidits.end());
  cout << max << endl;
  return 0;
}


#include <iostream>
using namespace std;

#define MAX 200000

int main() {
  int N, r[MAX];

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> r[i];
  }
  long long max = -1000000000000;
  for (int j = N - 1; j >= 0; j--) {
    if (max < r[j])
      for (int i = 0; j > i; i++) {
        if (max < r[j] - r[i])
          max = r[j] - r[i];
      }
  }
  cout << max << endl;

  return 0;
}

#include <iostream>
using namespace std;
#define MAX 200010
int main() {
  int N, r[MAX], min[MAX], max[MAX];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> r[i];
  }
  min[0] = r[0];
  for (int i = 1; i < N; i++) {
    if (r[i] < min[i - 1])
      min[i] = r[i];
    else
      min[i] = min[i - 1];
  }
  max[N - 1] = r[N - 1];
  for (int i = N - 2; i >= 0; i--) {
    if (r[i] > max[i + 1])
      max[i] = r[i];
    else
      max[i] = max[i + 1];
  }
  int ans = max[1] - min[0];
  for (int i = 0; i < N - 1; i++) {
    if (ans < (max[i + 1] - min[i]))
      ans = max[i + 1] - min[i];
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <vector>

// テストケースで、速度に対してのものがどのようになるか見てみたいので
// 敢えてベタな方法（速度が遅い）で投稿してみる。

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

  std::vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> v[i];
  }
  int max = v[1] - v[0];
  for (int j = 1; j < n; ++j) {
    for (int i = 0; i < j; ++i) {
      int tmp = v[j] - v[i];
      if (tmp > max) {
        max = tmp;
      }
    }
  }
  std::cout << max << std::endl;
  return 0;
}

#include <iostream>
#include <limits>

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

  int min;
  std::cin >> min;
  int max = std::numeric_limits<int>::min();
  for (int i = 1; i < n; ++i) {
    int val;
    std::cin >> val;
    int tmp = val - min;
    if (tmp > max) {
      max = tmp;
    }
    if (val < min) {
      min = val;
    }
  }
  std::cout << max << std::endl;
  return 0;
}


#include <limits.h>
#include <stdio.h>

int main(void) {
  int n, i, tmp, tmp2;
  int profit = INT_MIN;
  int min = INT_MAX;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &tmp);
    tmp2 = tmp - min;
    if (tmp2 > profit) {
      profit = tmp2;
    }
    if (tmp < min)
      min = tmp;
  }
  return profit;
}

#include <limits.h>
#include <stdio.h>

int main(void) {
  int n, i, tmp, tmp2;
  int profit = INT_MIN;
  int min = INT_MAX;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &tmp);
    tmp2 = tmp - min;
    if (tmp2 > profit) {
      profit = tmp2;
    }
    if (tmp < min)
      min = tmp;
  }
  printf("%d\\n", profit);
  return 0;
}


#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <stdlib.h>
#include <string>
#include <typeinfo>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  int n, max = -2147483648, diff;
  cin >> n;
  // cout << "n = " << n << endl;
  std::vector<int> a(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      diff = a[j] - a[i];
      if (diff > max) {
        max = diff;
        // cout << "new max = " << max << endl;
      }
    }
  }

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

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <stdlib.h>
#include <string>
#include <typeinfo>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  int n, max, max_diff = -2147483648, diff;
  cin >> n;
  // cout << "n = " << n << endl;
  std::vector<int> a(n + 1), b(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  // 最大値のリストb[]
  max = a[n - 1];
  for (int i = n - 1; i > 0; i--) {
    if (i == n - 1) {
      // 何もしない
      b[i] = a[i];
    } else {
      if (a[i] > max) {
        max = a[i];
      }
      b[i] = max;
    }
  }

  for (int i = 0; i < n - 1; i++) {
    diff = b[i + 1] - a[i];
    // cout << "diff = " << diff << endl;
    if (diff > max_diff) {
      max_diff = diff;
      // cout << "new max = " << max << endl;
    }
  }

  cout << max_diff << endl;
  return 0;
}


#include <iostream>
#define MAX_N 200000
using namespace std;

int calc(int a, int b);

int main(void) {
  int n;
  int profits[MAX_N + 1];

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

  int _max = -2000000000;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int val = calc(profits[i], profits[j]);
      _max = max(_max, val);
    }
  }

  cout << _max << endl;

  return 0;
}

int calc(int a, int b) { return b - a; }

#include <iostream>
#define MAX_N 200000
using namespace std;

int main(void) {
  int n;
  int profits[MAX_N + 1];

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

  int _max = -2000000000;
  int _min = profits[0];
  for (int i = 1; i < n; i++) {
    _max = max(_max, profits[i] - _min);
    _min = min(_min, profits[i]);
  }

  cout << _max << endl;

  return 0;
}


#include <iostream>

void call(int n) {
  int max = -1000000000;
  int *array = new int[n];
  for (int i = 0; i < n; i++) {
    std::cin >> array[i];
  }
  for (int j = 1; j < n; j++) {
    for (int i = 0; i < j; i++) {
      if (max < array[j] - array[i]) {
        max = array[j] - array[i];
      }
    }
  }
  std::cout << max << std::endl;
}

int main() {

  int n;
  while (std::cin >> n) {
    call(n);
  }
  return 0;
}

#include <iostream>

int main() {

  int n;
  while (std::cin >> n) {
    int *array = new int[n];
    for (int i = 0; i < n; i++) {
      std::cin >> array[i];
    }
    int maxv = array[1] - array[0];
    int minj;
    if (maxv < 0) {
      minj = array[1];
    } else {
      minj = array[0];
    }
    for (int j = 2; j < n; j++) {
      if (minj > array[j - 1]) {
        minj = array[j - 1];
      }
      if (maxv < array[j] - minj) {
        maxv = array[j] - minj;
      }
    }
    std::cout << maxv << std::endl;
    delete[] array;
  }
  return 0;
}


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

long long MaxProfit(int n, long long *Rt) {
  long long max = LLONG_MIN;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      long long tmp = Rt[j] - Rt[i];
      if (max < tmp)
        max = tmp;
    }
  }
  return max;
}

int main() {

  int n;
  cin >> n;
  long long Rt[n];
  long long max;
  for (int i = 0; i < n; i++)
    cin >> Rt[i];
  max = MaxProfit(n, Rt);
  cout << max << endl;
  return 0;
};

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

long long MaxProfit(int n, long long *Rt) {
  long long max = LLONG_MIN;
  long long MinRt = Rt[0];
  for (int j = 1; j < n; j++) {
    long long tmp = Rt[j] - MinRt;
    if (max < tmp)
      max = tmp;
    if (MinRt > Rt[j])
      MinRt = Rt[j];
  }
  return max;
}

int main() {

  int n;
  cin >> n;
  long long Rt[n];
  long long max;
  for (int i = 0; i < n; i++)
    cin >> Rt[i];
  max = MaxProfit(n, Rt);
  cout << max << endl;
  return 0;
};


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, f, n) for (int i = (f); i <= (n); ++i)
#define outl(x) cout << (x) << '\\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
template <class A, class B> inline bool chmax(A &a, B b) {
  return b > a ? a = b, 1 : 0;
}
template <class A, class B> inline bool chmin(A &a, B b) {
  return b < a ? a = b, 1 : 0;
}
inline int updiv(int a, int b) { return ((a + b - 1) / b); }

int N, a[200002];

int main() {
  FAST();
  cin >> N;
  rep(i, N) cin >> a[i];

  int maxv = INT_MIN;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      chmax(maxv, a[j] - a[i]);
    }
  }

  outl(maxv);
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, f, n) for (int i = (f); i <= (n); ++i)
#define outl(x) cout << (x) << '\\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
template <class A, class B> inline bool chmax(A &a, B b) {
  return b > a ? a = b, 1 : 0;
}
template <class A, class B> inline bool chmin(A &a, B b) {
  return b < a ? a = b, 1 : 0;
}
inline int updiv(int a, int b) { return ((a + b - 1) / b); }

int main() {
  FAST();
  int N, a;
  int ans = INT_MIN;
  int minv = INT_MAX;
  cin >> N;
  rep(i, N) {
    cin >> a;
    chmax(ans, a - minv);
    chmin(minv, a);
  }
  outl(ans);
}


#include <algorithm>
#include <iostream>
using namespace std;
static const int N = 10000;

int main() {

  int a[N], n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int minv = a[0];
  int maxv = a[1] - 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 <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

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

  int maxv = a[1] - a[0];
  int minv = a[0];

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

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

  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>
#include <vector>

class MaximumProfit {
private:
  std::vector<int> dataSet;

public:
  MaximumProfit(std::vector<int> vec);
  int getProfit();
};

MaximumProfit::MaximumProfit(std::vector<int> vec) { this->dataSet = vec; }

int MaximumProfit::getProfit() {
  int maxv = dataSet[1] - dataSet[0];
  for (int j = 1; j < dataSet.size(); j++) {
    for (int i = 0; i <= j - 1; i++) {
      if (maxv < (dataSet[j] - dataSet[i])) {
        maxv = dataSet[j] - dataSet[i];
      }
    }
  }
  return maxv;
}

int main() {

  int line;

  std::cin >> line;

  std::vector<int> vec;

  for (int i = 0; i < line; i++) {
    int input;
    std::cin >> input;
    vec.push_back(input);
  }

  MaximumProfit mp = MaximumProfit(vec);

  std::cout << mp.getProfit() << std::endl;

  return 0;
}

#include <iostream>
#include <vector>

class MaximumProfit {
private:
  std::vector<int> dataSet;

public:
  MaximumProfit(std::vector<int> vec);
  int getProfit();
  int getMaximum(int x, int y);
  int getMinimum(int x, int y);
};

MaximumProfit::MaximumProfit(std::vector<int> vec) { this->dataSet = vec; }

/*
int MaximumProfit::getProfit(){
    int maxv = dataSet[1] - dataSet[0];
    for(int j = 1;j < dataSet.size();j++){
        for(int i = 0;i <= j - 1;i++){
            if(maxv < (dataSet[j] - dataSet[i])){
                maxv = dataSet[j] - dataSet[i];
            }
        }
    }
    return maxv;
}
*/

int MaximumProfit::getProfit() {
  int maxv = dataSet[1] - dataSet[0];
  int minv = dataSet[0];
  for (int j = 1; j <= dataSet.size() - 1; j++) {
    maxv = getMaximum(maxv, dataSet[j] - minv);
    minv = getMinimum(minv, dataSet[j]);
  }
  return maxv;
}

int MaximumProfit::getMaximum(int x, int y) {
  if (x > y) {
    return x;
  }
  return y;
}

int MaximumProfit::getMinimum(int x, int y) {
  if (x < y) {
    return x;
  }
  return y;
}

int main() {

  int line;

  std::cin >> line;

  std::vector<int> vec;

  for (int i = 0; i < line; i++) {
    int input;
    std::cin >> input;
    vec.push_back(input);
  }

  MaximumProfit mp = MaximumProfit(vec);

  std::cout << mp.getProfit() << std::endl;

  return 0;
}


#include <bits/stdc++.h>

int main() {
  int n;
  int r[200000];
  int max = -1e9;

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

#include <iostream>

using namespace std;

int main() {
  int n;
  int r[200000];
  int max;
  int min;

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


#pragma GCC optimize "O3"
#include <algorithm>
#include <bitset>
#include <cctype>
#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 <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define whole(f, x, ...)                                                       \\
  ([&](decltype((x)) whole) {                                                  \\
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \\
  })(x)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REP_FROM(i, m, n) for (int i = (m); (i) < int(n); ++(i))
#define REP_REV(i, n) for (int i = (n)-1; (i) >= 0; --(i))
#define REP_FROMREV(i, m, n) for (int i = (n)-1; (i) >= int(m); --(i))
#define CLR(a) memset((a), 0, sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
#ifndef LOCAL
#define cerr                                                                   \\
  if (false)                                                                   \\
  cerr
#endif
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T> inline T sqr(T x) { return x * x; }
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

template <class T> inline void setmax(T &a, T const &b) { a = max(a, b); }
template <class T> inline void setmin(T &a, T const &b) { a = min(a, b); }
template <class T> T sq(T x) { return x * x; }
template <class T> T clamp(T a, T l, T r) {
  return min(max(a, l), r);
} // [l, r]
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main(int argc, char *argv[]) {
  // Something to do
  int n;
  cin >> n;

  LL max = -INFINITY;

  int ary[n];
  REP(i, n) {
    cin >> ary[i];
    REP(j, i) {
      LL diff = ary[i] - ary[j];
      if (diff > max)
        max = diff;
    }
  }

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

#pragma GCC optimize "O3"
#include <algorithm>
#include <bitset>
#include <cctype>
#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 <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define whole(f, x, ...)                                                       \\
  ([&](decltype((x)) whole) {                                                  \\
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \\
  })(x)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REP_FROM(i, m, n) for (int i = (m); (i) < int(n); ++(i))
#define REP_REV(i, n) for (int i = (n)-1; (i) >= 0; --(i))
#define REP_FROMREV(i, m, n) for (int i = (n)-1; (i) >= int(m); --(i))
#define CLR(a) memset((a), 0, sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
#ifndef LOCAL
#define cerr                                                                   \\
  if (false)                                                                   \\
  cerr
#endif
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T> inline T sqr(T x) { return x * x; }
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

template <class T> inline void setmax(T &a, T const &b) { a = max(a, b); }
template <class T> inline void setmin(T &a, T const &b) { a = min(a, b); }
template <class T> T sq(T x) { return x * x; }
template <class T> T clamp(T a, T l, T r) {
  return min(max(a, l), r);
} // [l, r]
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main(int argc, char *argv[]) {
  // Something to do
  int n;
  cin >> n;

  LL max = -INFINITY;
  LL input_min = INFINITY;

  int ary[n];
  REP(i, n) {
    cin >> ary[i];
    if (ary[i] - input_min > max)
      max = ary[i] - input_min;
    if (ary[i] < input_min)
      input_min = ary[i];
  }

  cout << max << 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 = 200000;

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

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

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

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

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


#include <algorithm>
#include <iostream>

using namespace std;

static const int MAX = 200000;

int main() {
  int num = 0, maxProfit = -1000000000;
  int value[MAX] = {0};

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

  for (int i = 0; i < num; i++) {
    for (int j = i + 1; j < num; j++) {
      maxProfit = max(maxProfit, value[j] - value[i]);
    }
  }

  cout << maxProfit << endl;

  return 0;
}

#include <algorithm>
#include <iostream>

using namespace std;

static const int MAX = 200000;

int main() {
  int num = 0, maxProfit = -1000000000;
  int value[MAX] = {0};

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

  int minValue = value[0];

  for (int i = 1; i < num; i++) {
    maxProfit = max(maxProfit, value[i] - minValue);
    minValue = min(minValue, value[i]);
  }

  cout << maxProfit << endl;

  return 0;
}


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

  int maxa = -10e09;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      maxa = max(maxa, a[j] - a[i]); // 大きい方を
    }
  }
  cout << maxa << endl;

  return 0;
}

// i<jとなるiとj全ても組み合わせに対するRj-Riを調べてる。

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

  int maxa = -10e09;
  int minv = a[0];

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

  cout << maxa << endl;

  return 0;
}


#include <iostream>
using namespace std;
int main() {
  int n, i, j, r[200000];
  long long v, max = -1000000000;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> r[i];
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      v = r[j] - r[i];
      if (v > max) {
        max = v;
      }
    }
  }
  cout << max << endl;

  return 0;
}

#include <iostream>
using namespace std;
int main() {
  int n, i, j, r[200000];
  long long v, max = -1000000000, min = 1000000000;

  // get number
  cin >> n;

  // get max1,2&min1,2
  for (i = 0; i < n; i++) {
    cin >> r[i];
  }

  min = r[0];

  for (i = 1; i < n; i++) {
    v = r[i] - min;
    if (v >= max) {
      max = v;
    }
    if (r[i] <= min) {
      min = r[i];
    }
  }

  cout << max << endl;

  return 0;
}


#include <algorithm>
#include <cstdio>

using namespace std;

const int kMax = 200000 + 5;

int num[kMax];

int main() {
  int n, res;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &num[i]);
    if (i == 1)
      res = num[1] - num[0];
    else {
      for (int j = 0; j < i; ++j) {
        res = max(num[i] - num[j], res);
      }
    }
  }
  printf("%d\\n", res);
  return 0;
}

#include <algorithm>
#include <cstdio>

using namespace std;

const int kMax = 200000 + 5;

int num[kMax];

int main() {
  int n, res, min_num;
  scanf("%d", &n);
  scanf("%d", &num[0]);
  min_num = num[0];
  for (int i = 1; i < n; ++i) {
    scanf("%d", &num[i]);
    if (i == 1)
      res = num[1] - min_num;
    else {
      res = max(res, num[i] - min_num);
    }
    min_num = min(min_num, num[i]);
  }
  printf("%d\\n", res);
  return 0;
}


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

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

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

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

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

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

  vector<int> v(n);

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


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> Vector;
typedef vector<vector<ll>> DVector;

#define fi first
#define se second
#define pb push_back
#define INF INT_MAX
#define bcnt __builtin_popcount
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define ub(x, y) upper_bound(all(x), y) - x.begin()
#define lb(x, y) lower_bound(all(x), y) - x.begin()
#define uni(x) x.erase(unique(all(x)), x.end())
#define rep(i, n) repl(i, 0, n - 1)
#define repl(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); i++)
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define exist(x, y) (find(all(x), y) != x.end())
#define each(itr, v) for (auto itr : v)
#define usort(x) sort(all(x))
#define dsort(x) sort(all(x), greater<int>())
#define mkp(x, y) make_pair(x, y)

int main() {
  cin.sync_with_stdio(false);
  int n;
  cin >> n;
  Vector a(n);
  int mx = -INF;
  rep(i, n) cin >> a[i];
  rep(i, n) rep(j, i) maxch(mx, a[i] - a[j]);
  cout << mx << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> Vector;
typedef vector<vector<ll>> DVector;

#define fi first
#define se second
#define pb push_back
#define INF INT_MAX
#define bcnt __builtin_popcount
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define ub(x, y) upper_bound(all(x), y) - x.begin()
#define lb(x, y) lower_bound(all(x), y) - x.begin()
#define uni(x) x.erase(unique(all(x)), x.end())
#define rep(i, n) repl(i, 0, n - 1)
#define repl(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); i++)
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define exist(x, y) (find(all(x), y) != x.end())
#define each(itr, v) for (auto itr : v)
#define usort(x) sort(all(x))
#define dsort(x) sort(all(x), greater<int>())
#define mkp(x, y) make_pair(x, y)

int main() {
  cin.sync_with_stdio(false);
  int n;
  cin >> n;
  Vector a(n);
  int mx = -INF;
  rep(i, n) cin >> a[i];
  Vector table(n);
  table[0] = a[0];
  repl(i, 1, n - 1) table[i] = mmin(table[i - 1], a[i]);
  repl(i, 1, n - 1) maxch(mx, a[i] - table[i - 1]);
  cout << mx << endl;
}


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

int main() {
  int n;
  scanf("%d", &n);
  int R[n];
  int i, j;
  int max;
  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[j] - R[i] > max) {
        max = R[j] - R[i];
      }
    }
  }

  printf("%d\\n", max);
}

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

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

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

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

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

  printf("%d\\n", max);
}


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

#include <iostream>
int main() {
  int input[2], keep, n, max;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      std::cin >> input[0];
      continue;
    }
    if (i == 1) {
      std::cin >> input[1];
      max = input[1] - input[0];
      continue;
    }
    std::cin >> keep;
    if (input[0] > input[1])
      input[0] = input[1];
    input[1] = keep;
    if (input[1] - input[0] > max)
      max = input[1] - input[0];
  }
  std::cout << max << "\\n";
  return 0;
}


#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 j = 1; j < n; j++) {
    maxv = max(maxv, R[j] - minv);
    minv = min(minv, R[j]);
  }

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

#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 j = 1; j < n; j++) {
    maxv = max(maxv, R[j] - minv);
    minv = min(minv, R[j]);
  }

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


#include <iostream>
using namespace std;

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

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

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

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

#include <iostream>
using namespace std;

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

  int r;
  int maxv = 0;
  int minv = 0;

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

    if (i == 0) {
      minv = r;
      continue;
    }

    if (maxv < r - minv or maxv == 0) {
      maxv = r - minv;
    }
    if (minv > r) {
      minv = r;
    }
  }

  cout << maxv << endl;

  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n, t, i, dr;

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

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

  for (t = n - 1; t > 1; t--) {
    for (i = 0; (i < t); i++) {
      dr = r[t] - r[i];
      if (dr > mx)
        mx = dr;
    }
  }

  cout << mx << endl;
}

#include <iostream>
using namespace std;

int main() {
  int n, t, i, dr;
  int mx_el = 0;

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

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

  for (t = n - 1; t > 1; t--) {
    if (r[t] > mx_el) {
      mx_el = r[t];
      for (i = 0; (i < t); i++) {
        dr = r[t] - r[i];
        if (dr > mx)
          mx = dr;
      }
    }
  }

  cout << mx << endl;
}


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

int maxProfit(vector<int> &array);

int main() {
  int size;
  vector<int> array;
  cin >> size;
  for (int i = 0; i < size; i++) {
    int tmp;
    cin >> tmp;
    array.push_back(tmp);
  }
  cout << maxProfit(array) << endl;
  return 0;
}

int maxProfit(vector<int> &array) {
  int max_val = array[1] - array[0];
  for (int i = 0; i < array.size() - 1; i++) {
    for (int j = i + 1; j < array.size(); j++) {
      int now = array[j] - array[i];
      if (now > max_val) {
        max_val = now;
      }
    }
  }
  return max_val;
}

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

int maxProfit(vector<int> &array);

int main() {
  int size;
  vector<int> array;
  cin >> size;
  for (int i = 0; i < size; i++) {
    int tmp;
    cin >> tmp;
    array.push_back(tmp);
  }
  cout << maxProfit(array) << endl;
  return 0;
}

int maxProfit(vector<int> &array) {
  int min = array[1] > array[0] ? array[0] : array[1];
  int max_val = array[1] - array[0];
  for (int i = 2; i < array.size(); i++) {
    int profit = array[i] - min;
    if (profit > max_val) {
      max_val = profit;
    }
    if (min > array[i]) {
      min = array[i];
    }
  }
  return max_val;
}


#include <stdio.h>
#include <stdlib.h>

#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, b, a) for (int i = (b)-1; i >= (a); i--)
#define chino(a, n)                                                            \\
  int n, *a;                                                                   \\
  scanf("%d", &n);                                                             \\
  a = (int *)malloc(sizeof(int) * n);                                          \\
  for (int i = 0; i < n; i++)                                                  \\
  scanf("%d", a + i)

int main() {
  chino(a, n);
  int ans = INT_MIN;
  REP(i, n) FOR(j, i + 1, n) if (a[j] - a[i] > ans) ans = a[j] - a[i];
  printf("%d\\n", ans);
}

#include <stdio.h>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, b, a) for (int i = (b)-1; i >= (a); i--)
#define STRS(i, str) for (int i = 0; (str)[i]; i++)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAXI(a, b)                                                             \\
  if (a < (b))                                                                 \\
  a = (b)
#define MINI(a, b)                                                             \\
  if (a > (b))                                                                 \\
  a = (b)

int main() {
  int n;
  int a;
  int min, max;
  scanf("%d%d%d", &n, &min, &a);
  max = a - min;
  MINI(min, a);
  FOR(i, 2, n) {
    scanf("%d", &a);
    MAXI(max, a - min);
    MINI(min, a);
  }
  printf("%d\\n", max);
}


#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a[200000];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = -9999999999999;
  for (int i = 0; i < n; i++) {
    for (int s = i + 1; s < n; s++) {
      // if (a[s] <= a[i])continue;
      ans = max(a[s] - a[i], ans);
    }
  }
  cout << ans << endl;
}

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a[200005];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int maa = 0;
  int memo[200005];
  for (int i = n - 1; i != 0; i--) {
    maa = max(maa, a[i]);
    memo[i - 1] = maa;
  }
  int ans = -1000000000;
  for (int i = 0; i < n - 1; i++) {
    ans = max(memo[i] - a[i], ans);
  }
  cout << ans << endl;
  return 0;
}


#include <algorithm>
#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 m = (1 << 31);
  for (int i = 0; i < n; i++) {
    for (int j = i - 1; j >= 0; j--) {
      m = max(a[i] - a[j], m);
    }
  }
  cout << m << endl;
  delete[] a;
  return 0;
}

#include <algorithm>
#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 m = (1 << 31);
  int minx = a[0];
  for (int i = 1; i < n; i++) {
    m = max(m, a[i] - minx);
    minx = min(minx, a[i]);
  }
  cout << m << endl;
  delete[] a;
  return 0;
}


#include <math.h>
#include <stdio.h>

int max(int *, int);

int main() {
  int n, i;
  scanf("%d", &n);
  int R[200001];
  for (i = 0; i <= n; i++) {
    scanf("%d", &R[i]);
  }
  printf("%d\\n", max(R, n));
}

int max(int array[], int n) {
  int start, target;
  int champion = -1000000000, challenger;
  for (start = 0; start <= n - 2; start++) {
    int biggest = 0;
    for (target = start + 1; target <= n - 1; target++) {
      if (1000000000 - array[start] <= champion)
        break;
      if (array[target] > biggest)
        biggest = array[target];
    }
    challenger = biggest - array[start];
    if (challenger > champion)
      champion = challenger;
  }
  return champion;
}

#include <math.h>
#include <stdio.h>

int max(int *, int);

int main() {
  int n, i;
  scanf("%d", &n);
  int R[200001];
  for (i = 0; i <= n; i++) {
    scanf("%d", &R[i]);
  }
  printf("%d\\n", max(R, n));
}

int max(int array[], int n) {
  int r = 0, i = 0, k, biggest = 1, smallest = 1000000000,
      champion = -1000000000, challenger;
  while (1) {
    i = r;
    while (i <= n - 1) {

      if (i == r) {
        biggest = 1;
        i = r + 1;
      }
      if (array[i] >= biggest) {
        biggest = array[i];
        r = i;
      }
      i++;
    }
    for (k = 0; k <= r - 1; k++) {
      if (array[k] <= smallest)
        smallest = array[k];
    }
    challenger = biggest - smallest;
    if (champion <= challenger)
      champion = challenger;
    if (r == n - 1)
      break;
  }
  return champion;
}


#include <iostream>
#include <vector>

using namespace std;

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

  vector<int> inputs;
  for (int i = 0; i < cnt; i++) {
    int y;
    cin >> y;
    inputs.push_back(y);
  }

  int max_diff = 0;
  bool has_diff = false;
  int diff = 0;
  int now = 0;
  int before = 0;
  for (int i = 0; i < inputs.size(); i++) {
    diff = 0;
    for (int j = i + 1; j < inputs.size(); j++) {
      now = inputs[j];
      before = inputs[i];
      diff = now - before;
      if (has_diff == false) {
        max_diff = diff;
        has_diff = true;
      } else if (diff > max_diff) {
        max_diff = diff;
      }
    }
  }

  cout << max_diff << endl;
  return 0;
}

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

using namespace std;

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

  vector<int> inputs;
  for (int i = 0; i < cnt; i++) {
    int y;
    cin >> y;
    inputs.push_back(y);
  }

  int minv = inputs[0];
  int maxdiff = -1000000000;
  for (int i = 1; i < inputs.size(); i++) {
    maxdiff = max(maxdiff, inputs[i] - minv);
    minv = min(minv, inputs[i]);
  }

  cout << maxdiff << endl;
  return 0;
}


#include <iostream>
using namespace std;

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

#include <iostream>
using namespace std;

int main() {
  int r[200001], n, max, min;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }
  min = r[0];
  max = r[1] - 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;
}


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

int main() {
  int n;
  long long int num[200000], max1 = -1000000000;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      max1 = max(max1, (num[i] - num[j]));
    }
  }
  cout << max1 << endl;
  return 0;
}

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

int main() {
  int n;
  int num, max1 = -2000000000, min1 = 2000000000;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num;
    max1 = max(max1, (num - min1));
    min1 = min(min1, num);
  }
  cout << max1 << endl;
  return 0;
}


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

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

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

int main() {
  int n, rmin = 1000000000, drmax = -1000000000, i, j;
  cin >> n;
  vector<int> r(n);
  cin >> r[0];
  rmin = r[0];
  for (i = 1; i < n; i++) {
    cin >> r[i];
    if (drmax < r[i] - rmin)
      drmax = r[i] - rmin;
    if (rmin > r[i])
      rmin = r[i];
  }
  cout << drmax << endl;
  return 0;
}


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

int maximum_profit(int *r, int n) {
  int mini = r[0];
  int maxi = r[1] - r[0];
  for (int i = 1; i < n; i++) {
    maxi = max(maxi, r[i] - mini);
    mini = min(mini, r[i]);
  }

  return maxi;
}

int main(void) {
  int *r;
  r = new int[NMAX];

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

  int max = maximum_profit(r, n);
  cout << max << endl;

  delete r;
  return 0;
}

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

int maximum_profit(int *r, int n) {
  int mini = r[0];
  int maxi = r[1] - r[0];
  for (int i = 1; i < n; i++) {
    maxi = max(maxi, r[i] - mini);
    mini = min(mini, r[i]);
  }

  return maxi;
}

int main(void) {
  int *r;
  r = new int[NMAX];

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

  int max = maximum_profit(r, n);
  cout << max << endl;

  delete r;
  return 0;
}


#include <iostream>
using namespace std;
int main() {
  int num;
  cin >> num;
  int b[200000];
  int x, y;
  cin >> x;
  for (int i = 0; i < num - 1; i++) {
    cin >> y;
    b[i] = y - x;
  }
  int accum = -1000000000;
  for (int i = 0; i < num - 1; i++) {
    for (int j = i; j < num - 1; j++) {
      if (b[j] > accum)
        accum = b[j];
    }
    for (int j = i; j < num - 1; j++) {
      b[j + 1] -= b[i];
    }
  }
  cout << accum << 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 = -1000000000;
  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;
}


#define _CRT_SECURE_NO_WARNINGS
#define MAX_DATA 200000
#define MIN_DATA 2

#include <stdio.h>
#include <stdlib.h>

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

  int NUM;
  scanf("%d", &NUM);

  int *data;

  if (NUM >= MIN_DATA && NUM <= MAX_DATA) {
    data = (int *)malloc(sizeof(int) * NUM);
  } else {
    return 1;
  }

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

  int max = data[1] - data[0];

  for (int i = 0; i < NUM; i++) {
    for (int j = i + 1; j < NUM; j++) {
      int temp = data[j] - data[i];

      if (temp > max)
        max = temp;
    }
  }

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

  return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#define MAX_DATA 200000
#define MIN_DATA 2

#include <stdio.h>
#include <stdlib.h>

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

  int NUM;
  scanf("%d", &NUM);

  int *data;

  if (NUM >= MIN_DATA && NUM <= MAX_DATA) {
    data = (int *)malloc(sizeof(int) * NUM);
  } else {
    return 1;
  }

  int max = -1000000000;
  int min = 0;
  int temp;

  scanf("%d", &min);

  for (int i = 1; i < NUM; i++) {
    scanf("%d", &temp);

    int sub = temp - min;

    if (sub > max) {
      max = sub;
    }

    if (temp < min) {
      min = temp;
    }
  }

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

  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 = R[1] - R[0];
  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 = R[1] - R[0];
  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 <cassert>
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int count;
  cin >> count;
  int *nums = new int[count];
  for (int i = 0; i < count; i++) {
    cin >> nums[i];
  }

  assert(count >= 2);
  if (count < 2) {
    return 1;
  }

  int maxprofit = nums[1] - nums[0];

  for (int i = 0; i < count - 1; i++) {
    for (int j = i + 1; j < count; j++) {
      int profit = nums[j] - nums[i];
      if (maxprofit < profit) {
        maxprofit = profit;
      }
    }
  }
  cout << maxprofit << endl;

  delete[] nums;
  return 0;
}

#include <cassert>
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int count;
  cin >> count;
  int *nums = new int[count];
  for (int i = 0; i < count; i++) {
    cin >> nums[i];
  }

  assert(count >= 2);
  if (count < 2) {
    return 1;
  }

  int maxprofit = -nums[0];
  int maxprofit_buy = nums[0];
  int min_buy = nums[0];

  for (int i = 1; i < count; i++) {
    int profit = nums[i] - min_buy;
    if (maxprofit < profit) {
      maxprofit_buy = min_buy;
    }
    if (nums[i] < min_buy) {
      min_buy = nums[i];
    }
    profit = nums[i] - maxprofit_buy;
    if (maxprofit < profit) {
      maxprofit = profit;
    }
  }
  cout << maxprofit << endl;

  delete[] nums;
  return 0;
}


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

template <typename T> T Input() {
  T value;
  std::cin >> value;
  return value;
}

int main() {
  int num, max = INT_MIN;
  std::vector<int> arr(200000);
  std::cin >> num;
  for (auto i = 0; i < num; ++i)
    arr[i] = Input<int>();
  for (auto i = 0; i < num; ++i) {
    for (auto j = num - 1; j > i; --j) {
      if (max < arr[j] - arr[i])
        max = arr[j] - arr[i];
    }
  }

  std::cout << max << "\\n";

  return 0;
}

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

template <typename T> T Input() {
  T value;
  std::cin >> value;
  return value;
}

int main() {
  std::ios::sync_with_stdio(false);
  int num, max, min;
  std::vector<int> arr(200000);
  std::cin >> num;
  for (auto i = 0; i < num; ++i)
    arr[i] = Input<int>();
  min = arr[0];
  max = INT_MIN;
  for (auto i = 1; i < num; ++i) {
    max = std::max(max, arr[i] - min);
    min = std::min(min, arr[i]);
  }

  std::cout << max << "\\n";

  return 0;
}


#include <stdio.h>

int main(void) {
  int n;
  scanf("%d", &n);

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

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

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

  return 0;
}

#include <stdio.h>

int main(void) {
  int n;
  scanf("%d", &n);

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

  int minv = R[0];
  int max_gap = R[1] - R[0];

  for (int i = 1; i < n; i++) {
    if (max_gap < R[i] - minv) {
      max_gap = R[i] - minv;
    }
    if (R[i] < minv) {
      minv = R[i];
    }
  }

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

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> s(n);
  for (int i = 0; i < n; i++)
    cin >> s[i];
  for (int i = 0; i < n - 1; i++) {
    s[i] = *max_element(s.begin() + i + 1, s.end()) - s[i];
  }
  cout << *max_element(s.begin(), s.end() - 1) << endl;
}

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> s(n + 1), m(n + 1, 0), a(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = n - 2; i >= 0; i--) {
    m[i] = max(m[i + 1], s[i + 1]);
    a[i] = m[i] - s[i];
  }
  cout << *max_element(a.begin(), a.end() - 1) << endl;
}


#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> a;
  int n, m, max;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m;
    a.push_back(m);
  }
  max = a[1] - a[0];
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[j] - a[i] > max)
        max = a[j] - a[i];
    }
  }
  cout << max << endl;
  return 0;
}

#include <iostream>
using namespace std;
int main() {
  int n, m, min, max = 1 - 1000000000;
  cin >> n;
  cin >> m;
  min = m;
  while (--n) {
    cin >> m;
    if (m - min > max)
      max = m - min;
    if (m < min)
      min = m;
  }
  cout << max << endl;
  return 0;
}