public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int[] r;
    int min, max, tmp, i;

    n = sc.nextInt();
    r = new int[n];
    for(i = 0;i < n;i++){
      r[i] = sc.nextInt();
    }

    min = r[0];
    max = r[1];
    tmp = r[0];
    if(r[1] < r[0])tmp = r[1];
    for(i = 2;i < n;i++){
      if(r[i] - tmp > max - min){
        max = r[i];
        min = tmp;
      }
      if(r[i] < tmp){
        tmp = r[i];
      }
    }

    System.out.println(max - min);

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int[] r;
    int min, max, tmp, i;

    n = sc.nextInt();
    r = new int[n];
    for(i = 0;i < n;i++){
      r[i] = sc.nextInt();
    }

    min = r[0];
    max = r[1];
    tmp = r[0];
    if(r[1] < r[0])tmp = r[1];
    for(i = 2;i < n;i++){
      if(r[i] - tmp > max - min){
        max = r[i];
        min = tmp;
      }
      if(r[i] < tmp){
        tmp = r[i];
      }
    }

    System.out.println(max - min);

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} Main public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int[] r;
    int min, max, tmp, i;

    n = sc.nextInt();
    r = new int[n];
    for(i = 0;i < n;i++){
      r[i] = sc.nextInt();
    }

    min = r[0];
    max = r[1];
    tmp = r[0];
    if(r[1] < r[0])tmp = r[1];
    for(i = 2;i < n;i++){
      if(r[i] - tmp > max - min){
        max = r[i];
        min = tmp;
      }
      if(r[i] < tmp){
        tmp = r[i];
      }
    }

    System.out.println(max - min);

    sc.close();
  } run {
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int[] r;
    int min, max, tmp, i;

    n = sc.nextInt();
    r = new int[n];
    for(i = 0;i < n;i++){
      r[i] = sc.nextInt();
    }

    min = r[0];
    max = r[1];
    tmp = r[0];
    if(r[1] < r[0])tmp = r[1];
    for(i = 2;i < n;i++){
      if(r[i] - tmp > max - min){
        max = r[i];
        min = tmp;
      }
      if(r[i] < tmp){
        tmp = r[i];
      }
    }

    System.out.println(max - min);

    sc.close();
  } java.util.Scanner sc = new java.util.Scanner(in); sc new java.util.Scanner(in) int n; n int[] r; r int min min max max tmp tmp i; i n = sc.nextInt() n sc.nextInt() sc.nextInt sc r = new int[n] r new int[n] n for(i = 0;i < n;i++){
      r[i] = sc.nextInt();
    } i = 0; 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 min = r[0] min r[0] r 0 max = r[1] max r[1] r 1 tmp = r[0] tmp r[0] r 0 if(r[1] < r[0])tmp = r[1]; r[1] < r[0] r[1] r 1 r[0] r 0 tmp = r[1] tmp r[1] r 1 for(i = 2;i < n;i++){
      if(r[i] - tmp > max - min){
        max = r[i];
        min = tmp;
      }
      if(r[i] < tmp){
        tmp = r[i];
      }
    } i = 2; i = 2 i 2 i < n i n i++ i++ i {
      if(r[i] - tmp > max - min){
        max = r[i];
        min = tmp;
      }
      if(r[i] < tmp){
        tmp = r[i];
      }
    } {
      if(r[i] - tmp > max - min){
        max = r[i];
        min = tmp;
      }
      if(r[i] < tmp){
        tmp = r[i];
      }
    } if(r[i] - tmp > max - min){
        max = r[i];
        min = tmp;
      } r[i] - tmp > max - min r[i] - tmp r[i] r i tmp max - min max min {
        max = r[i];
        min = tmp;
      } max = r[i] max r[i] r i min = tmp min tmp if(r[i] < tmp){
        tmp = r[i];
      } r[i] < tmp r[i] r i tmp {
        tmp = r[i];
      } tmp = r[i] tmp r[i] r i System.out.println(max - min) System.out.println System.out System System.out max - min max min sc.close() sc.close sc java.io.InputStream in in java.io.PrintStream out out public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  } main {
    (new Main()).run(System.in, System.out);
  } (new Main()).run(System.in, System.out) (new Main()).run (new Main()) System.in System System.in System.out System System.out String[] args args public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int[] r;
    int min, max, tmp, i;

    n = sc.nextInt();
    r = new int[n];
    for(i = 0;i < n;i++){
      r[i] = sc.nextInt();
    }

    min = r[0];
    max = r[1];
    tmp = r[0];
    if(r[1] < r[0])tmp = r[1];
    for(i = 2;i < n;i++){
      if(r[i] - tmp > max - min){
        max = r[i];
        min = tmp;
      }
      if(r[i] < tmp){
        tmp = r[i];
      }
    }

    System.out.println(max - min);

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int[] r;
    int min, max, tmp, i;

    n = sc.nextInt();
    r = new int[n];
    for(i = 0;i < n;i++){
      r[i] = sc.nextInt();
    }

    min = r[0];
    max = r[1];
    tmp = r[0];
    if(r[1] < r[0])tmp = r[1];
    for(i = 2;i < n;i++){
      if(r[i] - tmp > max - min){
        max = r[i];
        min = tmp;
      }
      if(r[i] < tmp){
        tmp = r[i];
      }
    }

    System.out.println(max - min);

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} Main
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int[] r;
    int min, max, tmp, i;

    n = sc.nextInt();
    r = new int[n];
    for(i = 0;i < n;i++){
      r[i] = sc.nextInt();
    }

    min = r[0];
    max = r[1];
    tmp = r[0];
    if(r[1] < r[0])tmp = r[1];
    for(i = 2;i < n;i++){
      if(r[i] - tmp > max - min){
        max = r[i];
        min = tmp;
      }
      if(r[i] < tmp){
        tmp = r[i];
      }
    }

    System.out.println(max - min);

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}