import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns = new int[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        int min = ns[0];
        int max = ns[1]-ns[0];
        for(int i=1;i<n;i++) {
        	if(max < ns[i]-min) {
        		max = ns[i]-min;
        	}
        	if(ns[i] < min) {
        		min = ns[i];
        	}
        }
        System.out.println(max);
        scan.close();
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns = new int[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        int min = ns[0];
        int max = ns[1]-ns[0];
        for(int i=1;i<n;i++) {
        	if(max < ns[i]-min) {
        		max = ns[i]-min;
        	}
        	if(ns[i] < min) {
        		min = ns[i];
        	}
        }
        System.out.println(max);
        scan.close();
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns = new int[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        int min = ns[0];
        int max = ns[1]-ns[0];
        for(int i=1;i<n;i++) {
        	if(max < ns[i]-min) {
        		max = ns[i]-min;
        	}
        	if(ns[i] < min) {
        		min = ns[i];
        	}
        }
        System.out.println(max);
        scan.close();
    } main {
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns = new int[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        int min = ns[0];
        int max = ns[1]-ns[0];
        for(int i=1;i<n;i++) {
        	if(max < ns[i]-min) {
        		max = ns[i]-min;
        	}
        	if(ns[i] < min) {
        		min = ns[i];
        	}
        }
        System.out.println(max);
        scan.close();
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = Integer.valueOf(scan.next()); n Integer.valueOf(scan.next()) Integer.valueOf Integer scan.next() scan.next scan int[] ns = new int[n]; ns new int[n] n for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
        	ns[i] = Integer.valueOf(scan.next());
        } {
        	ns[i] = Integer.valueOf(scan.next());
        } ns[i] = Integer.valueOf(scan.next()) ns[i] ns i Integer.valueOf(scan.next()) Integer.valueOf Integer scan.next() scan.next scan int min = ns[0]; min ns[0] ns 0 int max = ns[1]-ns[0]; max ns[1]-ns[0] ns[1] ns 1 ns[0] ns 0 for(int i=1;i<n;i++) {
        	if(max < ns[i]-min) {
        		max = ns[i]-min;
        	}
        	if(ns[i] < min) {
        		min = ns[i];
        	}
        } int i=1; int i=1; i 1 i<n i n i++ i++ i {
        	if(max < ns[i]-min) {
        		max = ns[i]-min;
        	}
        	if(ns[i] < min) {
        		min = ns[i];
        	}
        } {
        	if(max < ns[i]-min) {
        		max = ns[i]-min;
        	}
        	if(ns[i] < min) {
        		min = ns[i];
        	}
        } if(max < ns[i]-min) {
        		max = ns[i]-min;
        	} max < ns[i]-min max ns[i]-min ns[i] ns i min {
        		max = ns[i]-min;
        	} max = ns[i]-min max ns[i]-min ns[i] ns i min if(ns[i] < min) {
        		min = ns[i];
        	} ns[i] < min ns[i] ns i min {
        		min = ns[i];
        	} min = ns[i] min ns[i] ns i System.out.println(max) System.out.println System.out System System.out max scan.close() scan.close scan String[] args args public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns = new int[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        int min = ns[0];
        int max = ns[1]-ns[0];
        for(int i=1;i<n;i++) {
        	if(max < ns[i]-min) {
        		max = ns[i]-min;
        	}
        	if(ns[i] < min) {
        		min = ns[i];
        	}
        }
        System.out.println(max);
        scan.close();
    }
} public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns = new int[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        int min = ns[0];
        int max = ns[1]-ns[0];
        for(int i=1;i<n;i++) {
        	if(max < ns[i]-min) {
        		max = ns[i]-min;
        	}
        	if(ns[i] < min) {
        		min = ns[i];
        	}
        }
        System.out.println(max);
        scan.close();
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns = new int[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        int min = ns[0];
        int max = ns[1]-ns[0];
        for(int i=1;i<n;i++) {
        	if(max < ns[i]-min) {
        		max = ns[i]-min;
        	}
        	if(ns[i] < min) {
        		min = ns[i];
        	}
        }
        System.out.println(max);
        scan.close();
    }
}
