import java.util.Scanner;

public class Main{
   
    
    public static void main(String[] args){
        int n;
        int[] R;
        
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        R = new int[n];
  
        for( int i = 0; i < n; i++) R[i] = sc.nextInt();
        
        int a = R[1] - R[0];
        int m = R[0];
        for ( int i = 1; i < n; i++){
            if (R[i] - m > a ) a = R[i] - m;
            if (R[i] < m ) m = R[i];
    }
    System.out.println(a);
  
    }
} import java.util.Scanner; Scanner java.util public class Main{
   
    
    public static void main(String[] args){
        int n;
        int[] R;
        
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        R = new int[n];
  
        for( int i = 0; i < n; i++) R[i] = sc.nextInt();
        
        int a = R[1] - R[0];
        int m = R[0];
        for ( int i = 1; i < n; i++){
            if (R[i] - m > a ) a = R[i] - m;
            if (R[i] < m ) m = R[i];
    }
    System.out.println(a);
  
    }
} Main public static void main(String[] args){
        int n;
        int[] R;
        
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        R = new int[n];
  
        for( int i = 0; i < n; i++) R[i] = sc.nextInt();
        
        int a = R[1] - R[0];
        int m = R[0];
        for ( int i = 1; i < n; i++){
            if (R[i] - m > a ) a = R[i] - m;
            if (R[i] < m ) m = R[i];
    }
    System.out.println(a);
  
    } main {
        int n;
        int[] R;
        
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        R = new int[n];
  
        for( int i = 0; i < n; i++) R[i] = sc.nextInt();
        
        int a = R[1] - R[0];
        int m = R[0];
        for ( int i = 1; i < n; i++){
            if (R[i] - m > a ) a = R[i] - m;
            if (R[i] < m ) m = R[i];
    }
    System.out.println(a);
  
    } int n; n int[] R; R Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc 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] R i sc.nextInt() sc.nextInt sc int a = R[1] - R[0]; a R[1] - R[0] R[1] R 1 R[0] R 0 int m = R[0]; m R[0] R 0 for ( int i = 1; i < n; i++){
            if (R[i] - m > a ) a = R[i] - m;
            if (R[i] < m ) m = R[i];
    } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            if (R[i] - m > a ) a = R[i] - m;
            if (R[i] < m ) m = R[i];
    } {
            if (R[i] - m > a ) a = R[i] - m;
            if (R[i] < m ) m = R[i];
    } if (R[i] - m > a ) a = R[i] - m; R[i] - m > a R[i] - m R[i] R i m a a = R[i] - m a R[i] - m R[i] R i m if (R[i] < m ) m = R[i]; R[i] < m R[i] R i m m = R[i] m R[i] R i System.out.println(a) System.out.println System.out System System.out a String[] args args public class Main{
   
    
    public static void main(String[] args){
        int n;
        int[] R;
        
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        R = new int[n];
  
        for( int i = 0; i < n; i++) R[i] = sc.nextInt();
        
        int a = R[1] - R[0];
        int m = R[0];
        for ( int i = 1; i < n; i++){
            if (R[i] - m > a ) a = R[i] - m;
            if (R[i] < m ) m = R[i];
    }
    System.out.println(a);
  
    }
} public class Main{
   
    
    public static void main(String[] args){
        int n;
        int[] R;
        
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        R = new int[n];
  
        for( int i = 0; i < n; i++) R[i] = sc.nextInt();
        
        int a = R[1] - R[0];
        int m = R[0];
        for ( int i = 1; i < n; i++){
            if (R[i] - m > a ) a = R[i] - m;
            if (R[i] < m ) m = R[i];
    }
    System.out.println(a);
  
    }
} Main
import java.util.Scanner;

public class Main{
   
    
    public static void main(String[] args){
        int n;
        int[] R;
        
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        R = new int[n];
  
        for( int i = 0; i < n; i++) R[i] = sc.nextInt();
        
        int a = R[1] - R[0];
        int m = R[0];
        for ( int i = 1; i < n; i++){
            if (R[i] - m > a ) a = R[i] - m;
            if (R[i] < m ) m = R[i];
    }
    System.out.println(a);
  
    }
}