import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {
  public static void main(String[] args) {
    int i, j;
    Scanner sc = new Scanner(System.in); 
    int n = Integer.parseInt(sc.next());;
    int r[] = new int[n];
    for (i=0; i<n; i++)
      r[i] = Integer.parseInt(sc.next());;

    //res???max-min???????????????(???????????????mini?????´??°??§???????????¨???????????????)
    int res = r[1] - r[0];
    int mini = r[0];
    for (j=1; j<n; j++) {
      if (res < r[j] - mini) res = r[j] - mini;
      if (r[j] < mini) mini = r[j];
    }

    System.out.println(res);
  }
}

/*
  //O(n^2):TLE
  int res = r[1] - r[0];
  for (i=0; i<n-1; i++)
  for (j=i+1; j<n; j++)
    res = (res < r[j] - r[i]) ? r[j] - r[i] : res; 
  printf("%d\n", res);
*/
   
/*
  //WA(mini???????¨??????´??°?????????maxj-mini????????????????????¨?????????)
  int maxj = r[1];
  int mini = r[0];
  for (j=1; j<n; j++) {
    if (maxj-mini < r[j]-mini) {
    maxj = r[j];
    if (j < n-1 && r[j] < mini) mini = r[j];
    }
  //    if (j < n-1 && r[j] < mini) mini = r[j];
  }
  printf("%d\n", maxj-mini);
*/ import java.util.*; util.* java import java.io.*; io.* java import static java.util.Arrays.*; import static java.util.Arrays.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.util.Collections.*; import static java.util.Collections.*; import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; public class Main {
  public static void main(String[] args) {
    int i, j;
    Scanner sc = new Scanner(System.in); 
    int n = Integer.parseInt(sc.next());;
    int r[] = new int[n];
    for (i=0; i<n; i++)
      r[i] = Integer.parseInt(sc.next());;

    //res???max-min???????????????(???????????????mini?????´??°??§???????????¨???????????????)
    int res = r[1] - r[0];
    int mini = r[0];
    for (j=1; j<n; j++) {
      if (res < r[j] - mini) res = r[j] - mini;
      if (r[j] < mini) mini = r[j];
    }

    System.out.println(res);
  }
} Main public static void main(String[] args) {
    int i, j;
    Scanner sc = new Scanner(System.in); 
    int n = Integer.parseInt(sc.next());;
    int r[] = new int[n];
    for (i=0; i<n; i++)
      r[i] = Integer.parseInt(sc.next());;

    //res???max-min???????????????(???????????????mini?????´??°??§???????????¨???????????????)
    int res = r[1] - r[0];
    int mini = r[0];
    for (j=1; j<n; j++) {
      if (res < r[j] - mini) res = r[j] - mini;
      if (r[j] < mini) mini = r[j];
    }

    System.out.println(res);
  } main {
    int i, j;
    Scanner sc = new Scanner(System.in); 
    int n = Integer.parseInt(sc.next());;
    int r[] = new int[n];
    for (i=0; i<n; i++)
      r[i] = Integer.parseInt(sc.next());;

    //res???max-min???????????????(???????????????mini?????´??°??§???????????¨???????????????)
    int res = r[1] - r[0];
    int mini = r[0];
    for (j=1; j<n; j++) {
      if (res < r[j] - mini) res = r[j] - mini;
      if (r[j] < mini) mini = r[j];
    }

    System.out.println(res);
  } int i i j; j Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int r[] = new int[n]; r new int[n] n for (i=0; i<n; i++)
      r[i] = Integer.parseInt(sc.next()); i=0; i=0 i 0 i<n i n i++ i++ i r[i] = Integer.parseInt(sc.next()); r[i] = Integer.parseInt(sc.next()) r[i] r i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int res = r[1] - r[0]; res r[1] - r[0] r[1] r 1 r[0] r 0 int mini = r[0]; mini r[0] r 0 for (j=1; j<n; j++) {
      if (res < r[j] - mini) res = r[j] - mini;
      if (r[j] < mini) mini = r[j];
    } j=1; j=1 j 1 j<n j n j++ j++ j {
      if (res < r[j] - mini) res = r[j] - mini;
      if (r[j] < mini) mini = r[j];
    } {
      if (res < r[j] - mini) res = r[j] - mini;
      if (r[j] < mini) mini = r[j];
    } if (res < r[j] - mini) res = r[j] - mini; res < r[j] - mini res r[j] - mini r[j] r j mini res = r[j] - mini res r[j] - mini r[j] r j mini if (r[j] < mini) mini = r[j]; r[j] < mini r[j] r j mini mini = r[j] mini r[j] r j System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main {
  public static void main(String[] args) {
    int i, j;
    Scanner sc = new Scanner(System.in); 
    int n = Integer.parseInt(sc.next());;
    int r[] = new int[n];
    for (i=0; i<n; i++)
      r[i] = Integer.parseInt(sc.next());;

    //res???max-min???????????????(???????????????mini?????´??°??§???????????¨???????????????)
    int res = r[1] - r[0];
    int mini = r[0];
    for (j=1; j<n; j++) {
      if (res < r[j] - mini) res = r[j] - mini;
      if (r[j] < mini) mini = r[j];
    }

    System.out.println(res);
  }
} public class Main {
  public static void main(String[] args) {
    int i, j;
    Scanner sc = new Scanner(System.in); 
    int n = Integer.parseInt(sc.next());;
    int r[] = new int[n];
    for (i=0; i<n; i++)
      r[i] = Integer.parseInt(sc.next());;

    //res???max-min???????????????(???????????????mini?????´??°??§???????????¨???????????????)
    int res = r[1] - r[0];
    int mini = r[0];
    for (j=1; j<n; j++) {
      if (res < r[j] - mini) res = r[j] - mini;
      if (r[j] < mini) mini = r[j];
    }

    System.out.println(res);
  }
} Main
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {
  public static void main(String[] args) {
    int i, j;
    Scanner sc = new Scanner(System.in); 
    int n = Integer.parseInt(sc.next());;
    int r[] = new int[n];
    for (i=0; i<n; i++)
      r[i] = Integer.parseInt(sc.next());;

    //res???max-min???????????????(???????????????mini?????´??°??§???????????¨???????????????)
    int res = r[1] - r[0];
    int mini = r[0];
    for (j=1; j<n; j++) {
      if (res < r[j] - mini) res = r[j] - mini;
      if (r[j] < mini) mini = r[j];
    }

    System.out.println(res);
  }
}

/*
  //O(n^2):TLE
  int res = r[1] - r[0];
  for (i=0; i<n-1; i++)
  for (j=i+1; j<n; j++)
    res = (res < r[j] - r[i]) ? r[j] - r[i] : res; 
  printf("%d\n", res);
*/
   
/*
  //WA(mini???????¨??????´??°?????????maxj-mini????????????????????¨?????????)
  int maxj = r[1];
  int mini = r[0];
  for (j=1; j<n; j++) {
    if (maxj-mini < r[j]-mini) {
    maxj = r[j];
    if (j < n-1 && r[j] < mini) mini = r[j];
    }
  //    if (j < n-1 && r[j] < mini) mini = r[j];
  }
  printf("%d\n", maxj-mini);
*/