import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

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[] r = new int[n];

		for(int i = 0; i < n; i++){
			r[i] = Integer.parseInt(br.readLine());
		}

		int min = r[0];
		int max = Integer.MIN_VALUE;

		for(int i = 1; i < n; i++){
			max = Math.max(max, r[i] - min);
			min = Math.min(min, r[i]);
		}

		System.out.println(max);

	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io 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[] r = new int[n];

		for(int i = 0; i < n; i++){
			r[i] = Integer.parseInt(br.readLine());
		}

		int min = r[0];
		int max = Integer.MIN_VALUE;

		for(int i = 1; i < n; i++){
			max = Math.max(max, r[i] - min);
			min = Math.min(min, r[i]);
		}

		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[] r = new int[n];

		for(int i = 0; i < n; i++){
			r[i] = Integer.parseInt(br.readLine());
		}

		int min = r[0];
		int max = Integer.MIN_VALUE;

		for(int i = 1; i < n; i++){
			max = Math.max(max, r[i] - min);
			min = Math.min(min, r[i]);
		}

		System.out.println(max);

	} main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] r = new int[n];

		for(int i = 0; i < n; i++){
			r[i] = Integer.parseInt(br.readLine());
		}

		int min = r[0];
		int max = Integer.MIN_VALUE;

		for(int i = 1; i < n; i++){
			max = Math.max(max, r[i] - min);
			min = Math.min(min, r[i]);
		}

		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[] r = new int[n]; r new int[n] n for(int i = 0; i < n; i++){
			r[i] = Integer.parseInt(br.readLine());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			r[i] = Integer.parseInt(br.readLine());
		} {
			r[i] = Integer.parseInt(br.readLine());
		} r[i] = Integer.parseInt(br.readLine()) r[i] r i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int min = r[0]; min r[0] r 0 int max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE for(int i = 1; i < n; i++){
			max = Math.max(max, r[i] - min);
			min = Math.min(min, r[i]);
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			max = Math.max(max, r[i] - min);
			min = Math.min(min, r[i]);
		} {
			max = Math.max(max, r[i] - min);
			min = Math.min(min, r[i]);
		} max = Math.max(max, r[i] - min) max Math.max(max, r[i] - min) Math.max Math max r[i] - min r[i] r i min min = Math.min(min, r[i]) min Math.min(min, r[i]) Math.min Math min r[i] r i System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

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[] r = new int[n];

		for(int i = 0; i < n; i++){
			r[i] = Integer.parseInt(br.readLine());
		}

		int min = r[0];
		int max = Integer.MIN_VALUE;

		for(int i = 1; i < n; i++){
			max = Math.max(max, r[i] - min);
			min = Math.min(min, r[i]);
		}

		System.out.println(max);

	}

}