import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		
		int[] arr = new int[num];
		for(int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		int maxDif = Integer.MIN_VALUE;
		int maxNum;
		int smallerNum = arr[0];
		
		for(int i = 0; i < num; i++) {
			if (arr[i] <= smallerNum) {
				for(int j = i + 1; j < num; j++) {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				}
			smallerNum = arr[i];
			}
		}
		
		System.out.println(maxDif);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		
		int[] arr = new int[num];
		for(int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		int maxDif = Integer.MIN_VALUE;
		int maxNum;
		int smallerNum = arr[0];
		
		for(int i = 0; i < num; i++) {
			if (arr[i] <= smallerNum) {
				for(int j = i + 1; j < num; j++) {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				}
			smallerNum = arr[i];
			}
		}
		
		System.out.println(maxDif);
	}
} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		
		int[] arr = new int[num];
		for(int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		int maxDif = Integer.MIN_VALUE;
		int maxNum;
		int smallerNum = arr[0];
		
		for(int i = 0; i < num; i++) {
			if (arr[i] <= smallerNum) {
				for(int j = i + 1; j < num; j++) {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				}
			smallerNum = arr[i];
			}
		}
		
		System.out.println(maxDif);
	} main {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		
		int[] arr = new int[num];
		for(int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		int maxDif = Integer.MIN_VALUE;
		int maxNum;
		int smallerNum = arr[0];
		
		for(int i = 0; i < num; i++) {
			if (arr[i] <= smallerNum) {
				for(int j = i + 1; j < num; j++) {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				}
			smallerNum = arr[i];
			}
		}
		
		System.out.println(maxDif);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc int[] arr = new int[num]; arr new int[num] num for(int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
			arr[i] = sc.nextInt();
		} {
			arr[i] = sc.nextInt();
		} arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc int maxDif = Integer.MIN_VALUE; maxDif Integer.MIN_VALUE Integer Integer.MIN_VALUE int maxNum; maxNum int smallerNum = arr[0]; smallerNum arr[0] arr 0 for(int i = 0; i < num; i++) {
			if (arr[i] <= smallerNum) {
				for(int j = i + 1; j < num; j++) {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				}
			smallerNum = arr[i];
			}
		} int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
			if (arr[i] <= smallerNum) {
				for(int j = i + 1; j < num; j++) {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				}
			smallerNum = arr[i];
			}
		} {
			if (arr[i] <= smallerNum) {
				for(int j = i + 1; j < num; j++) {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				}
			smallerNum = arr[i];
			}
		} if (arr[i] <= smallerNum) {
				for(int j = i + 1; j < num; j++) {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				}
			smallerNum = arr[i];
			} arr[i] <= smallerNum arr[i] arr i smallerNum {
				for(int j = i + 1; j < num; j++) {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				}
			smallerNum = arr[i];
			} for(int j = i + 1; j < num; j++) {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				} int j = i + 1; int j = i + 1; j i + 1 i 1 j < num j num j++ j++ j {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				} {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				} maxDif = Math.max(maxDif, arr[j] - arr[i]) maxDif Math.max(maxDif, arr[j] - arr[i]) Math.max Math maxDif arr[j] - arr[i] arr[j] arr j arr[i] arr i smallerNum = arr[i] smallerNum arr[i] arr i System.out.println(maxDif) System.out.println System.out System System.out maxDif String[] args args public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		
		int[] arr = new int[num];
		for(int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		int maxDif = Integer.MIN_VALUE;
		int maxNum;
		int smallerNum = arr[0];
		
		for(int i = 0; i < num; i++) {
			if (arr[i] <= smallerNum) {
				for(int j = i + 1; j < num; j++) {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				}
			smallerNum = arr[i];
			}
		}
		
		System.out.println(maxDif);
	}
} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		
		int[] arr = new int[num];
		for(int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		int maxDif = Integer.MIN_VALUE;
		int maxNum;
		int smallerNum = arr[0];
		
		for(int i = 0; i < num; i++) {
			if (arr[i] <= smallerNum) {
				for(int j = i + 1; j < num; j++) {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				}
			smallerNum = arr[i];
			}
		}
		
		System.out.println(maxDif);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		
		int[] arr = new int[num];
		for(int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		int maxDif = Integer.MIN_VALUE;
		int maxNum;
		int smallerNum = arr[0];
		
		for(int i = 0; i < num; i++) {
			if (arr[i] <= smallerNum) {
				for(int j = i + 1; j < num; j++) {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				}
			smallerNum = arr[i];
			}
		}
		
		System.out.println(maxDif);
	}
}