import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] r = new int[n];
    for(int i = 0; i < n; i++)
      r[i] = stdIn.nextInt();

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

    System.out.println(maxv);
  }
} import java.util.Scanner; Scanner java.util class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] r = new int[n];
    for(int i = 0; i < n; i++)
      r[i] = stdIn.nextInt();

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

    System.out.println(maxv);
  }
} Main public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] r = new int[n];
    for(int i = 0; i < n; i++)
      r[i] = stdIn.nextInt();

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

    System.out.println(maxv);
  } main {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] r = new int[n];
    for(int i = 0; i < n; i++)
      r[i] = stdIn.nextInt();

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

    System.out.println(maxv);
  } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int[] r = new int[n]; r new int[n] n for(int i = 0; i < n; i++)
      r[i] = stdIn.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i r[i] = stdIn.nextInt(); r[i] = stdIn.nextInt() r[i] r i stdIn.nextInt() stdIn.nextInt stdIn int maxv = r[1] - r[0]; maxv r[1] - r[0] r[1] r 1 r[0] r 0 int minv = r[0]; minv r[0] r 0 for(int j = 1; j < n; j++){
      int diff = r[j] - minv;
      if(diff > maxv)
        maxv = diff;
      if(minv > r[j])
        minv = r[j];
    } int j = 1; int j = 1; j 1 j < n j n j++ j++ j {
      int diff = r[j] - minv;
      if(diff > maxv)
        maxv = diff;
      if(minv > r[j])
        minv = r[j];
    } {
      int diff = r[j] - minv;
      if(diff > maxv)
        maxv = diff;
      if(minv > r[j])
        minv = r[j];
    } int diff = r[j] - minv; diff r[j] - minv r[j] r j minv if(diff > maxv)
        maxv = diff; diff > maxv diff maxv maxv = diff maxv diff if(minv > r[j])
        minv = r[j]; minv > r[j] minv r[j] r j minv = r[j] minv r[j] r j System.out.println(maxv) System.out.println System.out System System.out maxv String[] args args
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] r = new int[n];
    for(int i = 0; i < n; i++)
      r[i] = stdIn.nextInt();

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

    System.out.println(maxv);
  }
}