import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve();
	}

	private static void solve() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] nums = new int[n];
		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		sc.close();
		int tmpMax = Integer.MIN_VALUE;
		int tmpMin = nums[0];

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

		System.out.println(tmpMax);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		solve();
	}

	private static void solve() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] nums = new int[n];
		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		sc.close();
		int tmpMax = Integer.MIN_VALUE;
		int tmpMin = nums[0];

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

		System.out.println(tmpMax);
	}
} Main public static void main(String[] args) {
		solve();
	} main {
		solve();
	} solve() solve String[] args args private static void solve() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] nums = new int[n];
		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		sc.close();
		int tmpMax = Integer.MIN_VALUE;
		int tmpMin = nums[0];

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

		System.out.println(tmpMax);
	} solve {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] nums = new int[n];
		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		sc.close();
		int tmpMax = Integer.MIN_VALUE;
		int tmpMin = nums[0];

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

		System.out.println(tmpMax);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] nums = new int[n]; nums new int[n] n for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			nums[i] = sc.nextInt();
		} {
			nums[i] = sc.nextInt();
		} nums[i] = sc.nextInt() nums[i] nums i sc.nextInt() sc.nextInt sc sc.close() sc.close sc int tmpMax = Integer.MIN_VALUE; tmpMax Integer.MIN_VALUE Integer Integer.MIN_VALUE int tmpMin = nums[0]; tmpMin nums[0] nums 0 for (int i = 1; i < n; i++) {
			tmpMax = Math.max(tmpMax, nums[i] - tmpMin);
			tmpMin = Math.min(tmpMin, nums[i]);
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			tmpMax = Math.max(tmpMax, nums[i] - tmpMin);
			tmpMin = Math.min(tmpMin, nums[i]);
		} {
			tmpMax = Math.max(tmpMax, nums[i] - tmpMin);
			tmpMin = Math.min(tmpMin, nums[i]);
		} tmpMax = Math.max(tmpMax, nums[i] - tmpMin) tmpMax Math.max(tmpMax, nums[i] - tmpMin) Math.max Math tmpMax nums[i] - tmpMin nums[i] nums i tmpMin tmpMin = Math.min(tmpMin, nums[i]) tmpMin Math.min(tmpMin, nums[i]) Math.min Math tmpMin nums[i] nums i System.out.println(tmpMax) System.out.println System.out System System.out tmpMax public class Main {
	public static void main(String[] args) {
		solve();
	}

	private static void solve() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] nums = new int[n];
		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		sc.close();
		int tmpMax = Integer.MIN_VALUE;
		int tmpMin = nums[0];

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

		System.out.println(tmpMax);
	}
} public class Main {
	public static void main(String[] args) {
		solve();
	}

	private static void solve() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] nums = new int[n];
		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		sc.close();
		int tmpMax = Integer.MIN_VALUE;
		int tmpMin = nums[0];

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

		System.out.println(tmpMax);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve();
	}

	private static void solve() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] nums = new int[n];
		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		sc.close();
		int tmpMax = Integer.MIN_VALUE;
		int tmpMin = nums[0];

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

		System.out.println(tmpMax);
	}
}