import java.util.*;

public 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 = r[1] - r[0];
    int min = r[0];
    for(int i = 1; i < n; i++) {
      min = Math.min(min, r[i - 1]);
      max = Math.max(max, r[i] - min);
    }
    System.out.println(max);
  }
}
 import java.util.*; util.* java public 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 = r[1] - r[0];
    int min = r[0];
    for(int i = 1; i < n; i++) {
      min = Math.min(min, r[i - 1]);
      max = Math.max(max, r[i] - min);
    }
    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 = r[1] - r[0];
    int min = r[0];
    for(int i = 1; i < n; i++) {
      min = Math.min(min, r[i - 1]);
      max = Math.max(max, r[i] - min);
    }
    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 = r[1] - r[0];
    int min = r[0];
    for(int i = 1; i < n; i++) {
      min = Math.min(min, r[i - 1]);
      max = Math.max(max, r[i] - min);
    }
    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 = r[1] - r[0]; max r[1] - r[0] r[1] r 1 r[0] r 0 int min = r[0]; min r[0] r 0 for(int i = 1; i < n; i++) {
      min = Math.min(min, r[i - 1]);
      max = Math.max(max, r[i] - min);
    } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
      min = Math.min(min, r[i - 1]);
      max = Math.max(max, r[i] - min);
    } {
      min = Math.min(min, r[i - 1]);
      max = Math.max(max, r[i] - min);
    } min = Math.min(min, r[i - 1]) min Math.min(min, r[i - 1]) Math.min Math min r[i - 1] r i - 1 i 1 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 System.out.println(max) System.out.println System.out System System.out max String[] args args public 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 = r[1] - r[0];
    int min = r[0];
    for(int i = 1; i < n; i++) {
      min = Math.min(min, r[i - 1]);
      max = Math.max(max, r[i] - min);
    }
    System.out.println(max);
  }
} public 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 = r[1] - r[0];
    int min = r[0];
    for(int i = 1; i < n; i++) {
      min = Math.min(min, r[i - 1]);
      max = Math.max(max, r[i] - min);
    }
    System.out.println(max);
  }
} Main
import java.util.*;

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

