import java.util.Scanner;

public class Main {
	
	public static void  main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = -999999999;
		int num;
		int sans;
		int minn = sc.nextInt();
		
		for (int i=0; i<N-1; i++) {
			num = sc.nextInt();
			sans = num - minn;
			if(ans < sans) ans = sans;
			if(minn > num) minn = num;
		}
		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	
	public static void  main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = -999999999;
		int num;
		int sans;
		int minn = sc.nextInt();
		
		for (int i=0; i<N-1; i++) {
			num = sc.nextInt();
			sans = num - minn;
			if(ans < sans) ans = sans;
			if(minn > num) minn = num;
		}
		System.out.println(ans);
	}
} Main public static void  main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = -999999999;
		int num;
		int sans;
		int minn = sc.nextInt();
		
		for (int i=0; i<N-1; i++) {
			num = sc.nextInt();
			sans = num - minn;
			if(ans < sans) ans = sans;
			if(minn > num) minn = num;
		}
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = -999999999;
		int num;
		int sans;
		int minn = sc.nextInt();
		
		for (int i=0; i<N-1; i++) {
			num = sc.nextInt();
			sans = num - minn;
			if(ans < sans) ans = sans;
			if(minn > num) minn = num;
		}
		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int ans = -999999999; ans -999999999 999999999 int num; num int sans; sans int minn = sc.nextInt(); minn sc.nextInt() sc.nextInt sc for (int i=0; i<N-1; i++) {
			num = sc.nextInt();
			sans = num - minn;
			if(ans < sans) ans = sans;
			if(minn > num) minn = num;
		} int i=0; int i=0; i 0 i<N-1 i N-1 N 1 i++ i++ i {
			num = sc.nextInt();
			sans = num - minn;
			if(ans < sans) ans = sans;
			if(minn > num) minn = num;
		} {
			num = sc.nextInt();
			sans = num - minn;
			if(ans < sans) ans = sans;
			if(minn > num) minn = num;
		} num = sc.nextInt() num sc.nextInt() sc.nextInt sc sans = num - minn sans num - minn num minn if(ans < sans) ans = sans; ans < sans ans sans ans = sans ans sans if(minn > num) minn = num; minn > num minn num minn = num minn num System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	
	public static void  main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = -999999999;
		int num;
		int sans;
		int minn = sc.nextInt();
		
		for (int i=0; i<N-1; i++) {
			num = sc.nextInt();
			sans = num - minn;
			if(ans < sans) ans = sans;
			if(minn > num) minn = num;
		}
		System.out.println(ans);
	}
} public class Main {
	
	public static void  main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = -999999999;
		int num;
		int sans;
		int minn = sc.nextInt();
		
		for (int i=0; i<N-1; i++) {
			num = sc.nextInt();
			sans = num - minn;
			if(ans < sans) ans = sans;
			if(minn > num) minn = num;
		}
		System.out.println(ans);
	}
} Main
import java.util.Scanner;

public class Main {
	
	public static void  main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = -999999999;
		int num;
		int sans;
		int minn = sc.nextInt();
		
		for (int i=0; i<N-1; i++) {
			num = sc.nextInt();
			sans = num - minn;
			if(ans < sans) ans = sans;
			if(minn > num) minn = num;
		}
		System.out.println(ans);
	}
}
