import java.util.*;

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

    int max = -2000000000;
    int min = r[0];
    for(int i = 1; i < n; i++){
      max = Math.max(max,r[i]-min);
      min = Math.min(min,r[i]);
    }
    System.out.println(max);
  }
}
 import java.util.*; util.* java class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] r = new int[n];
    for(int i = 0; i < n; i++){
      r[i] = sc.nextInt();
    }

    int max = -2000000000;
    int min = r[0];
    for(int i = 1; i < n; i++){
      max = Math.max(max,r[i]-min);
      min = Math.min(min,r[i]);
    }
    System.out.println(max);
  }
} Main public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] r = new int[n];
    for(int i = 0; i < n; i++){
      r[i] = sc.nextInt();
    }

    int max = -2000000000;
    int min = r[0];
    for(int i = 1; i < n; i++){
      max = Math.max(max,r[i]-min);
      min = Math.min(min,r[i]);
    }
    System.out.println(max);
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] r = new int[n];
    for(int i = 0; i < n; i++){
      r[i] = sc.nextInt();
    }

    int max = -2000000000;
    int min = r[0];
    for(int i = 1; i < n; i++){
      max = Math.max(max,r[i]-min);
      min = Math.min(min,r[i]);
    }
    System.out.println(max);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] r = new int[n]; r new int[n] n for(int i = 0; i < n; i++){
      r[i] = sc.nextInt();
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      r[i] = sc.nextInt();
    } {
      r[i] = sc.nextInt();
    } r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc int max = -2000000000; max -2000000000 2000000000 int min = r[0]; min r[0] r 0 for(int i = 1; i < n; i++){
      max = Math.max(max,r[i]-min);
      min = Math.min(min,r[i]);
    } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
      max = Math.max(max,r[i]-min);
      min = Math.min(min,r[i]);
    } {
      max = Math.max(max,r[i]-min);
      min = Math.min(min,r[i]);
    } max = Math.max(max,r[i]-min) max Math.max(max,r[i]-min) Math.max Math max r[i]-min r[i] r i min min = Math.min(min,r[i]) min Math.min(min,r[i]) Math.min Math min r[i] r i System.out.println(max) System.out.println System.out System System.out max String args[] args
import java.util.*;

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

    int max = -2000000000;
    int min = r[0];
    for(int i = 1; i < n; i++){
      max = Math.max(max,r[i]-min);
      min = Math.min(min,r[i]);
    }
    System.out.println(max);
  }
}

