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 min = r[0];
    int maxp = r[1] - r[0];
    for(int i = 1; i < n; i++){
      int prof = r[i] - min;
      if(prof > maxp)
        maxp = prof;
      if(r[i] < min)
        min = r[i];
    }

    System.out.println(maxp);
  }
} 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 min = r[0];
    int maxp = r[1] - r[0];
    for(int i = 1; i < n; i++){
      int prof = r[i] - min;
      if(prof > maxp)
        maxp = prof;
      if(r[i] < min)
        min = r[i];
    }

    System.out.println(maxp);
  }
} 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 min = r[0];
    int maxp = r[1] - r[0];
    for(int i = 1; i < n; i++){
      int prof = r[i] - min;
      if(prof > maxp)
        maxp = prof;
      if(r[i] < min)
        min = r[i];
    }

    System.out.println(maxp);
  } 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 min = r[0];
    int maxp = r[1] - r[0];
    for(int i = 1; i < n; i++){
      int prof = r[i] - min;
      if(prof > maxp)
        maxp = prof;
      if(r[i] < min)
        min = r[i];
    }

    System.out.println(maxp);
  } 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] = stdIn.nextInt() r[i] r i stdIn.nextInt() stdIn.nextInt stdIn int min = r[0]; min r[0] r 0 int maxp = r[1] - r[0]; maxp r[1] - r[0] r[1] r 1 r[0] r 0 for(int i = 1; i < n; i++){
      int prof = r[i] - min;
      if(prof > maxp)
        maxp = prof;
      if(r[i] < min)
        min = r[i];
    } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
      int prof = r[i] - min;
      if(prof > maxp)
        maxp = prof;
      if(r[i] < min)
        min = r[i];
    } {
      int prof = r[i] - min;
      if(prof > maxp)
        maxp = prof;
      if(r[i] < min)
        min = r[i];
    } int prof = r[i] - min; prof r[i] - min r[i] r i min if(prof > maxp)
        maxp = prof; prof > maxp prof maxp maxp = prof maxp prof if(r[i] < min)
        min = r[i]; r[i] < min r[i] r i min min = r[i] min r[i] r i System.out.println(maxp) System.out.println System.out System System.out maxp 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 min = r[0];
    int maxp = r[1] - r[0];
    for(int i = 1; i < n; i++){
      int prof = r[i] - min;
      if(prof > maxp)
        maxp = prof;
      if(r[i] < min)
        min = r[i];
    }

    System.out.println(maxp);
  }
}