import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(br.readLine());
    int[] a = new int[N];

    for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(br.readLine());
    }

    int min = a[0];
    int max = a[1]-a[0];

    for(int i = 0; i < N-1; i++){
      if(i == N - 1){
        min = minv(min, a[i-1]);
        max = maxv(max, a[i] - min);
      }else{
        min =  minv(min, a[i]);
        max = maxv(max, a[i+1] - min);
      }
    }


    System.out.println(max);
  }

  public static int minv(int min, int a){
    if(min >= a){
      return a;
    }else{
      return min;
    }
  }

  public static int maxv(int max, int a){
    if(max <= a)return a;
    else return max;
  }

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io class Main{

  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(br.readLine());
    int[] a = new int[N];

    for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(br.readLine());
    }

    int min = a[0];
    int max = a[1]-a[0];

    for(int i = 0; i < N-1; i++){
      if(i == N - 1){
        min = minv(min, a[i-1]);
        max = maxv(max, a[i] - min);
      }else{
        min =  minv(min, a[i]);
        max = maxv(max, a[i+1] - min);
      }
    }


    System.out.println(max);
  }

  public static int minv(int min, int a){
    if(min >= a){
      return a;
    }else{
      return min;
    }
  }

  public static int maxv(int max, int a){
    if(max <= a)return a;
    else return max;
  }

} Main public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(br.readLine());
    int[] a = new int[N];

    for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(br.readLine());
    }

    int min = a[0];
    int max = a[1]-a[0];

    for(int i = 0; i < N-1; i++){
      if(i == N - 1){
        min = minv(min, a[i-1]);
        max = maxv(max, a[i] - min);
      }else{
        min =  minv(min, a[i]);
        max = maxv(max, a[i+1] - min);
      }
    }


    System.out.println(max);
  } main {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(br.readLine());
    int[] a = new int[N];

    for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(br.readLine());
    }

    int min = a[0];
    int max = a[1]-a[0];

    for(int i = 0; i < N-1; i++){
      if(i == N - 1){
        min = minv(min, a[i-1]);
        max = maxv(max, a[i] - min);
      }else{
        min =  minv(min, a[i]);
        max = maxv(max, a[i+1] - min);
      }
    }


    System.out.println(max);
  } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int N = Integer.parseInt(br.readLine()); N Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] a = new int[N]; a new int[N] N for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(br.readLine());
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      a[i] = Integer.parseInt(br.readLine());
    } {
      a[i] = Integer.parseInt(br.readLine());
    } a[i] = Integer.parseInt(br.readLine()) a[i] a i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int min = a[0]; min a[0] a 0 int max = a[1]-a[0]; max a[1]-a[0] a[1] a 1 a[0] a 0 for(int i = 0; i < N-1; i++){
      if(i == N - 1){
        min = minv(min, a[i-1]);
        max = maxv(max, a[i] - min);
      }else{
        min =  minv(min, a[i]);
        max = maxv(max, a[i+1] - min);
      }
    } int i = 0; int i = 0; i 0 i < N-1 i N-1 N 1 i++ i++ i {
      if(i == N - 1){
        min = minv(min, a[i-1]);
        max = maxv(max, a[i] - min);
      }else{
        min =  minv(min, a[i]);
        max = maxv(max, a[i+1] - min);
      }
    } {
      if(i == N - 1){
        min = minv(min, a[i-1]);
        max = maxv(max, a[i] - min);
      }else{
        min =  minv(min, a[i]);
        max = maxv(max, a[i+1] - min);
      }
    } if(i == N - 1){
        min = minv(min, a[i-1]);
        max = maxv(max, a[i] - min);
      }else{
        min =  minv(min, a[i]);
        max = maxv(max, a[i+1] - min);
      } i == N - 1 i N - 1 N 1 {
        min = minv(min, a[i-1]);
        max = maxv(max, a[i] - min);
      } min = minv(min, a[i-1]) min minv(min, a[i-1]) minv min a[i-1] a i-1 i 1 max = maxv(max, a[i] - min) max maxv(max, a[i] - min) maxv max a[i] - min a[i] a i min {
        min =  minv(min, a[i]);
        max = maxv(max, a[i+1] - min);
      } min =  minv(min, a[i]) min minv(min, a[i]) minv min a[i] a i max = maxv(max, a[i+1] - min) max maxv(max, a[i+1] - min) maxv max a[i+1] - min a[i+1] a i+1 i 1 min System.out.println(max) System.out.println System.out System System.out max String[] args args public static int minv(int min, int a){
    if(min >= a){
      return a;
    }else{
      return min;
    }
  } minv {
    if(min >= a){
      return a;
    }else{
      return min;
    }
  } if(min >= a){
      return a;
    }else{
      return min;
    } min >= a min a {
      return a;
    } return a; a {
      return min;
    } return min; min int min min int a a public static int maxv(int max, int a){
    if(max <= a)return a;
    else return max;
  } maxv {
    if(max <= a)return a;
    else return max;
  } if(max <= a)return a;
    else return max; max <= a max a return a; a return max; max int max max int a a
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(br.readLine());
    int[] a = new int[N];

    for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(br.readLine());
    }

    int min = a[0];
    int max = a[1]-a[0];

    for(int i = 0; i < N-1; i++){
      if(i == N - 1){
        min = minv(min, a[i-1]);
        max = maxv(max, a[i] - min);
      }else{
        min =  minv(min, a[i]);
        max = maxv(max, a[i+1] - min);
      }
    }


    System.out.println(max);
  }

  public static int minv(int min, int a){
    if(min >= a){
      return a;
    }else{
      return min;
    }
  }

  public static int maxv(int max, int a){
    if(max <= a)return a;
    else return max;
  }

}