import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] num = new int[n];
		for (int i = 0; i<n ; i++ ) {
			num[i] = Integer.parseInt(br.readLine());
		}
		int max = num[1] - num[0];
		int min = num[0];
		for (int i = 1; i<n  ; i++) {
			min = Math.min(min,num[i-1]);
			max = Math.max(max,num[i]-min);
		}
		System.out.println(max);
	}
} import java.io.*; io.* java import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] num = new int[n];
		for (int i = 0; i<n ; i++ ) {
			num[i] = Integer.parseInt(br.readLine());
		}
		int max = num[1] - num[0];
		int min = num[0];
		for (int i = 1; i<n  ; i++) {
			min = Math.min(min,num[i-1]);
			max = Math.max(max,num[i]-min);
		}
		System.out.println(max);
	}
} Main public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] num = new int[n];
		for (int i = 0; i<n ; i++ ) {
			num[i] = Integer.parseInt(br.readLine());
		}
		int max = num[1] - num[0];
		int min = num[0];
		for (int i = 1; i<n  ; i++) {
			min = Math.min(min,num[i-1]);
			max = Math.max(max,num[i]-min);
		}
		System.out.println(max);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] num = new int[n];
		for (int i = 0; i<n ; i++ ) {
			num[i] = Integer.parseInt(br.readLine());
		}
		int max = num[1] - num[0];
		int min = num[0];
		for (int i = 1; i<n  ; i++) {
			min = Math.min(min,num[i-1]);
			max = Math.max(max,num[i]-min);
		}
		System.out.println(max);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] num = new int[n]; num new int[n] n for (int i = 0; i<n ; i++ ) {
			num[i] = Integer.parseInt(br.readLine());
		} int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
			num[i] = Integer.parseInt(br.readLine());
		} {
			num[i] = Integer.parseInt(br.readLine());
		} num[i] = Integer.parseInt(br.readLine()) num[i] num i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int max = num[1] - num[0]; max num[1] - num[0] num[1] num 1 num[0] num 0 int min = num[0]; min num[0] num 0 for (int i = 1; i<n  ; i++) {
			min = Math.min(min,num[i-1]);
			max = Math.max(max,num[i]-min);
		} int i = 1; int i = 1; i 1 i<n i n i++ i++ i {
			min = Math.min(min,num[i-1]);
			max = Math.max(max,num[i]-min);
		} {
			min = Math.min(min,num[i-1]);
			max = Math.max(max,num[i]-min);
		} min = Math.min(min,num[i-1]) min Math.min(min,num[i-1]) Math.min Math min num[i-1] num i-1 i 1 max = Math.max(max,num[i]-min) max Math.max(max,num[i]-min) Math.max Math max num[i]-min num[i] num i min System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] num = new int[n];
		for (int i = 0; i<n ; i++ ) {
			num[i] = Integer.parseInt(br.readLine());
		}
		int max = num[1] - num[0];
		int min = num[0];
		for (int i = 1; i<n  ; i++) {
			min = Math.min(min,num[i-1]);
			max = Math.max(max,num[i]-min);
		}
		System.out.println(max);
	}
}