import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int[] R = new int[n];
		for (int i=0; i < n; i++) {
			R[i] = sc.nextInt();
		}
//
//		int max = R[1] - R[0];
//		for (int i =0; i < n-1; i++) {
//			for (int j=i+1; j < n; j++) {
//				if (max < R[j] - R[i])
//				max = R[j] - R[i];
//			}
//		}
//
//		System.out.println(max);

		int max = R[1] - R[0];
		int i = 0;
		for ( int j=1; j < n; j++) {
			if ( R[j] - R[i] > max ) {
				max = R[j] - R[i];
			}
			if ( R[i] > R[j] ) {
				R[i] = R[j];
			}
		}

		System.out.println(max);

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int[] R = new int[n];
		for (int i=0; i < n; i++) {
			R[i] = sc.nextInt();
		}
//
//		int max = R[1] - R[0];
//		for (int i =0; i < n-1; i++) {
//			for (int j=i+1; j < n; j++) {
//				if (max < R[j] - R[i])
//				max = R[j] - R[i];
//			}
//		}
//
//		System.out.println(max);

		int max = R[1] - R[0];
		int i = 0;
		for ( int j=1; j < n; j++) {
			if ( R[j] - R[i] > max ) {
				max = R[j] - R[i];
			}
			if ( R[i] > R[j] ) {
				R[i] = R[j];
			}
		}

		System.out.println(max);

	}

} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int[] R = new int[n];
		for (int i=0; i < n; i++) {
			R[i] = sc.nextInt();
		}
//
//		int max = R[1] - R[0];
//		for (int i =0; i < n-1; i++) {
//			for (int j=i+1; j < n; j++) {
//				if (max < R[j] - R[i])
//				max = R[j] - R[i];
//			}
//		}
//
//		System.out.println(max);

		int max = R[1] - R[0];
		int i = 0;
		for ( int j=1; j < n; j++) {
			if ( R[j] - R[i] > max ) {
				max = R[j] - R[i];
			}
			if ( R[i] > R[j] ) {
				R[i] = R[j];
			}
		}

		System.out.println(max);

	} main {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int[] R = new int[n];
		for (int i=0; i < n; i++) {
			R[i] = sc.nextInt();
		}
//
//		int max = R[1] - R[0];
//		for (int i =0; i < n-1; i++) {
//			for (int j=i+1; j < n; j++) {
//				if (max < R[j] - R[i])
//				max = R[j] - R[i];
//			}
//		}
//
//		System.out.println(max);

		int max = R[1] - R[0];
		int i = 0;
		for ( int j=1; j < n; j++) {
			if ( R[j] - R[i] > max ) {
				max = R[j] - R[i];
			}
			if ( R[i] > R[j] ) {
				R[i] = R[j];
			}
		}

		System.out.println(max);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] R = new int[n]; R new int[n] n for (int i=0; i < n; i++) {
			R[i] = sc.nextInt();
		} int i=0; int i=0; i 0 i < n i n i++ i++ i {
			R[i] = sc.nextInt();
		} {
			R[i] = sc.nextInt();
		} R[i] = sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc int max = R[1] - R[0]; max R[1] - R[0] R[1] R 1 R[0] R 0 int i = 0; i 0 for ( int j=1; j < n; j++) {
			if ( R[j] - R[i] > max ) {
				max = R[j] - R[i];
			}
			if ( R[i] > R[j] ) {
				R[i] = R[j];
			}
		} int j=1; int j=1; j 1 j < n j n j++ j++ j {
			if ( R[j] - R[i] > max ) {
				max = R[j] - R[i];
			}
			if ( R[i] > R[j] ) {
				R[i] = R[j];
			}
		} {
			if ( R[j] - R[i] > max ) {
				max = R[j] - R[i];
			}
			if ( R[i] > R[j] ) {
				R[i] = R[j];
			}
		} if ( R[j] - R[i] > max ) {
				max = R[j] - R[i];
			} R[j] - R[i] > max R[j] - R[i] R[j] R j R[i] R i max {
				max = R[j] - R[i];
			} max = R[j] - R[i] max R[j] - R[i] R[j] R j R[i] R i if ( R[i] > R[j] ) {
				R[i] = R[j];
			} R[i] > R[j] R[i] R i R[j] R j {
				R[i] = R[j];
			} R[i] = R[j] R[i] R i R[j] R j System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int[] R = new int[n];
		for (int i=0; i < n; i++) {
			R[i] = sc.nextInt();
		}
//
//		int max = R[1] - R[0];
//		for (int i =0; i < n-1; i++) {
//			for (int j=i+1; j < n; j++) {
//				if (max < R[j] - R[i])
//				max = R[j] - R[i];
//			}
//		}
//
//		System.out.println(max);

		int max = R[1] - R[0];
		int i = 0;
		for ( int j=1; j < n; j++) {
			if ( R[j] - R[i] > max ) {
				max = R[j] - R[i];
			}
			if ( R[i] > R[j] ) {
				R[i] = R[j];
			}
		}

		System.out.println(max);

	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int[] R = new int[n];
		for (int i=0; i < n; i++) {
			R[i] = sc.nextInt();
		}
//
//		int max = R[1] - R[0];
//		for (int i =0; i < n-1; i++) {
//			for (int j=i+1; j < n; j++) {
//				if (max < R[j] - R[i])
//				max = R[j] - R[i];
//			}
//		}
//
//		System.out.println(max);

		int max = R[1] - R[0];
		int i = 0;
		for ( int j=1; j < n; j++) {
			if ( R[j] - R[i] > max ) {
				max = R[j] - R[i];
			}
			if ( R[i] > R[j] ) {
				R[i] = R[j];
			}
		}

		System.out.println(max);

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int[] R = new int[n];
		for (int i=0; i < n; i++) {
			R[i] = sc.nextInt();
		}
//
//		int max = R[1] - R[0];
//		for (int i =0; i < n-1; i++) {
//			for (int j=i+1; j < n; j++) {
//				if (max < R[j] - R[i])
//				max = R[j] - R[i];
//			}
//		}
//
//		System.out.println(max);

		int max = R[1] - R[0];
		int i = 0;
		for ( int j=1; j < n; j++) {
			if ( R[j] - R[i] > max ) {
				max = R[j] - R[i];
			}
			if ( R[i] > R[j] ) {
				R[i] = R[j];
			}
		}

		System.out.println(max);

	}

}