import java.util.*;
//import java.util.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int A[] = new int[n];
    int i,j;
    
    for(i = 0; i < n; i++){
        A[i] = sc.nextInt();
       // System.out.println(A[i]);
    }
    
    int min = A[0];
    int maxv = A[1] - A[0];
    
    for(i = 1; i < n; i++){
        if((A[i] - min) > maxv){
            maxv = (A[i] - min);
        }
        if(A[i] < min){
            min = A[i];
        }
    }
    
    System.out.println(maxv);

    }
}
 import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int A[] = new int[n];
    int i,j;
    
    for(i = 0; i < n; i++){
        A[i] = sc.nextInt();
       // System.out.println(A[i]);
    }
    
    int min = A[0];
    int maxv = A[1] - A[0];
    
    for(i = 1; i < n; i++){
        if((A[i] - min) > maxv){
            maxv = (A[i] - min);
        }
        if(A[i] < min){
            min = A[i];
        }
    }
    
    System.out.println(maxv);

    }
} Main public static void main(String[] args) throws Exception {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int A[] = new int[n];
    int i,j;
    
    for(i = 0; i < n; i++){
        A[i] = sc.nextInt();
       // System.out.println(A[i]);
    }
    
    int min = A[0];
    int maxv = A[1] - A[0];
    
    for(i = 1; i < n; i++){
        if((A[i] - min) > maxv){
            maxv = (A[i] - min);
        }
        if(A[i] < min){
            min = A[i];
        }
    }
    
    System.out.println(maxv);

    } main {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int A[] = new int[n];
    int i,j;
    
    for(i = 0; i < n; i++){
        A[i] = sc.nextInt();
       // System.out.println(A[i]);
    }
    
    int min = A[0];
    int maxv = A[1] - A[0];
    
    for(i = 1; i < n; i++){
        if((A[i] - min) > maxv){
            maxv = (A[i] - min);
        }
        if(A[i] < min){
            min = A[i];
        }
    }
    
    System.out.println(maxv);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int A[] = new int[n]; A new int[n] n int i i j; j for(i = 0; i < n; i++){
        A[i] = sc.nextInt();
       // System.out.println(A[i]);
    } i = 0; i = 0 i 0 i < n i n i++ i++ i {
        A[i] = sc.nextInt();
       // System.out.println(A[i]);
    } {
        A[i] = sc.nextInt();
       // System.out.println(A[i]);
    } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc int min = A[0]; min A[0] A 0 int maxv = A[1] - A[0]; maxv A[1] - A[0] A[1] A 1 A[0] A 0 for(i = 1; i < n; i++){
        if((A[i] - min) > maxv){
            maxv = (A[i] - min);
        }
        if(A[i] < min){
            min = A[i];
        }
    } i = 1; i = 1 i 1 i < n i n i++ i++ i {
        if((A[i] - min) > maxv){
            maxv = (A[i] - min);
        }
        if(A[i] < min){
            min = A[i];
        }
    } {
        if((A[i] - min) > maxv){
            maxv = (A[i] - min);
        }
        if(A[i] < min){
            min = A[i];
        }
    } if((A[i] - min) > maxv){
            maxv = (A[i] - min);
        } (A[i] - min) > maxv (A[i] - min) A[i] A i min maxv {
            maxv = (A[i] - min);
        } maxv = (A[i] - min) maxv (A[i] - min) A[i] A i min if(A[i] < min){
            min = A[i];
        } A[i] < min A[i] A i min {
            min = A[i];
        } min = A[i] min A[i] A i System.out.println(maxv) System.out.println System.out System System.out maxv String[] args args public class Main {
    public static void main(String[] args) throws Exception {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int A[] = new int[n];
    int i,j;
    
    for(i = 0; i < n; i++){
        A[i] = sc.nextInt();
       // System.out.println(A[i]);
    }
    
    int min = A[0];
    int maxv = A[1] - A[0];
    
    for(i = 1; i < n; i++){
        if((A[i] - min) > maxv){
            maxv = (A[i] - min);
        }
        if(A[i] < min){
            min = A[i];
        }
    }
    
    System.out.println(maxv);

    }
} public class Main {
    public static void main(String[] args) throws Exception {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int A[] = new int[n];
    int i,j;
    
    for(i = 0; i < n; i++){
        A[i] = sc.nextInt();
       // System.out.println(A[i]);
    }
    
    int min = A[0];
    int maxv = A[1] - A[0];
    
    for(i = 1; i < n; i++){
        if((A[i] - min) > maxv){
            maxv = (A[i] - min);
        }
        if(A[i] < min){
            min = A[i];
        }
    }
    
    System.out.println(maxv);

    }
} Main
import java.util.*;
//import java.util.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int A[] = new int[n];
    int i,j;
    
    for(i = 0; i < n; i++){
        A[i] = sc.nextInt();
       // System.out.println(A[i]);
    }
    
    int min = A[0];
    int maxv = A[1] - A[0];
    
    for(i = 1; i < n; i++){
        if((A[i] - min) > maxv){
            maxv = (A[i] - min);
        }
        if(A[i] < min){
            min = A[i];
        }
    }
    
    System.out.println(maxv);

    }
}

