import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int[] minsL = new int[n+2];
		int[] maxsL = new int[n+2];
		int[] maxsR = new int[n+2];
		int[] minsR = new int[n+2];
		int[] kawase = new int[n+2];

		minsL[0] = Integer.MAX_VALUE;
		maxsL[0] = 0;
		for(int i=1;i<=n;i++) {
			kawase[i] = in.nextInt();
			minsL[i] = Math.min(minsL[i-1], kawase[i]);
			maxsL[i] = Math.max(maxsL[i-1], kawase[i]);
		}
		minsR[n+1] = Integer.MAX_VALUE;
		maxsR[n+1] = 0;
		for(int i=n;i>=1;i--) {
			minsR[i] = Math.min(minsR[i+1], kawase[i]);
			maxsR[i] = Math.max(maxsR[i+1], kawase[i]);
		}

		int ans = Integer.MIN_VALUE;
		for(int i=1;i<n;i++) {
			ans = Math.max(ans, maxsR[i+1] - minsL[i]);
//			ans = Math.max(ans, Math.abs(maxsL[i] - minsR[i+1]));
		}
		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int[] minsL = new int[n+2];
		int[] maxsL = new int[n+2];
		int[] maxsR = new int[n+2];
		int[] minsR = new int[n+2];
		int[] kawase = new int[n+2];

		minsL[0] = Integer.MAX_VALUE;
		maxsL[0] = 0;
		for(int i=1;i<=n;i++) {
			kawase[i] = in.nextInt();
			minsL[i] = Math.min(minsL[i-1], kawase[i]);
			maxsL[i] = Math.max(maxsL[i-1], kawase[i]);
		}
		minsR[n+1] = Integer.MAX_VALUE;
		maxsR[n+1] = 0;
		for(int i=n;i>=1;i--) {
			minsR[i] = Math.min(minsR[i+1], kawase[i]);
			maxsR[i] = Math.max(maxsR[i+1], kawase[i]);
		}

		int ans = Integer.MIN_VALUE;
		for(int i=1;i<n;i++) {
			ans = Math.max(ans, maxsR[i+1] - minsL[i]);
//			ans = Math.max(ans, Math.abs(maxsL[i] - minsR[i+1]));
		}
		System.out.println(ans);
	}
} Main public static void main(String args[]) {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int[] minsL = new int[n+2];
		int[] maxsL = new int[n+2];
		int[] maxsR = new int[n+2];
		int[] minsR = new int[n+2];
		int[] kawase = new int[n+2];

		minsL[0] = Integer.MAX_VALUE;
		maxsL[0] = 0;
		for(int i=1;i<=n;i++) {
			kawase[i] = in.nextInt();
			minsL[i] = Math.min(minsL[i-1], kawase[i]);
			maxsL[i] = Math.max(maxsL[i-1], kawase[i]);
		}
		minsR[n+1] = Integer.MAX_VALUE;
		maxsR[n+1] = 0;
		for(int i=n;i>=1;i--) {
			minsR[i] = Math.min(minsR[i+1], kawase[i]);
			maxsR[i] = Math.max(maxsR[i+1], kawase[i]);
		}

		int ans = Integer.MIN_VALUE;
		for(int i=1;i<n;i++) {
			ans = Math.max(ans, maxsR[i+1] - minsL[i]);
//			ans = Math.max(ans, Math.abs(maxsL[i] - minsR[i+1]));
		}
		System.out.println(ans);
	} main {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int[] minsL = new int[n+2];
		int[] maxsL = new int[n+2];
		int[] maxsR = new int[n+2];
		int[] minsR = new int[n+2];
		int[] kawase = new int[n+2];

		minsL[0] = Integer.MAX_VALUE;
		maxsL[0] = 0;
		for(int i=1;i<=n;i++) {
			kawase[i] = in.nextInt();
			minsL[i] = Math.min(minsL[i-1], kawase[i]);
			maxsL[i] = Math.max(maxsL[i-1], kawase[i]);
		}
		minsR[n+1] = Integer.MAX_VALUE;
		maxsR[n+1] = 0;
		for(int i=n;i>=1;i--) {
			minsR[i] = Math.min(minsR[i+1], kawase[i]);
			maxsR[i] = Math.max(maxsR[i+1], kawase[i]);
		}

		int ans = Integer.MIN_VALUE;
		for(int i=1;i<n;i++) {
			ans = Math.max(ans, maxsR[i+1] - minsL[i]);
//			ans = Math.max(ans, Math.abs(maxsL[i] - minsR[i+1]));
		}
		System.out.println(ans);
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int[] minsL = new int[n+2]; minsL new int[n+2] n+2 n 2 int[] maxsL = new int[n+2]; maxsL new int[n+2] n+2 n 2 int[] maxsR = new int[n+2]; maxsR new int[n+2] n+2 n 2 int[] minsR = new int[n+2]; minsR new int[n+2] n+2 n 2 int[] kawase = new int[n+2]; kawase new int[n+2] n+2 n 2 minsL[0] = Integer.MAX_VALUE minsL[0] minsL 0 Integer.MAX_VALUE Integer Integer.MAX_VALUE maxsL[0] = 0 maxsL[0] maxsL 0 0 for(int i=1;i<=n;i++) {
			kawase[i] = in.nextInt();
			minsL[i] = Math.min(minsL[i-1], kawase[i]);
			maxsL[i] = Math.max(maxsL[i-1], kawase[i]);
		} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
			kawase[i] = in.nextInt();
			minsL[i] = Math.min(minsL[i-1], kawase[i]);
			maxsL[i] = Math.max(maxsL[i-1], kawase[i]);
		} {
			kawase[i] = in.nextInt();
			minsL[i] = Math.min(minsL[i-1], kawase[i]);
			maxsL[i] = Math.max(maxsL[i-1], kawase[i]);
		} kawase[i] = in.nextInt() kawase[i] kawase i in.nextInt() in.nextInt in minsL[i] = Math.min(minsL[i-1], kawase[i]) minsL[i] minsL i Math.min(minsL[i-1], kawase[i]) Math.min Math minsL[i-1] minsL i-1 i 1 kawase[i] kawase i maxsL[i] = Math.max(maxsL[i-1], kawase[i]) maxsL[i] maxsL i Math.max(maxsL[i-1], kawase[i]) Math.max Math maxsL[i-1] maxsL i-1 i 1 kawase[i] kawase i minsR[n+1] = Integer.MAX_VALUE minsR[n+1] minsR n+1 n 1 Integer.MAX_VALUE Integer Integer.MAX_VALUE maxsR[n+1] = 0 maxsR[n+1] maxsR n+1 n 1 0 for(int i=n;i>=1;i--) {
			minsR[i] = Math.min(minsR[i+1], kawase[i]);
			maxsR[i] = Math.max(maxsR[i+1], kawase[i]);
		} int i=n; int i=n; i n i>=1 i 1 i-- i-- i {
			minsR[i] = Math.min(minsR[i+1], kawase[i]);
			maxsR[i] = Math.max(maxsR[i+1], kawase[i]);
		} {
			minsR[i] = Math.min(minsR[i+1], kawase[i]);
			maxsR[i] = Math.max(maxsR[i+1], kawase[i]);
		} minsR[i] = Math.min(minsR[i+1], kawase[i]) minsR[i] minsR i Math.min(minsR[i+1], kawase[i]) Math.min Math minsR[i+1] minsR i+1 i 1 kawase[i] kawase i maxsR[i] = Math.max(maxsR[i+1], kawase[i]) maxsR[i] maxsR i Math.max(maxsR[i+1], kawase[i]) Math.max Math maxsR[i+1] maxsR i+1 i 1 kawase[i] kawase i int ans = Integer.MIN_VALUE; ans Integer.MIN_VALUE Integer Integer.MIN_VALUE for(int i=1;i<n;i++) {
			ans = Math.max(ans, maxsR[i+1] - minsL[i]);
//			ans = Math.max(ans, Math.abs(maxsL[i] - minsR[i+1]));
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			ans = Math.max(ans, maxsR[i+1] - minsL[i]);
//			ans = Math.max(ans, Math.abs(maxsL[i] - minsR[i+1]));
		} {
			ans = Math.max(ans, maxsR[i+1] - minsL[i]);
//			ans = Math.max(ans, Math.abs(maxsL[i] - minsR[i+1]));
		} ans = Math.max(ans, maxsR[i+1] - minsL[i]) ans Math.max(ans, maxsR[i+1] - minsL[i]) Math.max Math ans maxsR[i+1] - minsL[i] maxsR[i+1] maxsR i+1 i 1 minsL[i] minsL i System.out.println(ans) System.out.println System.out System System.out ans String args[] args
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int[] minsL = new int[n+2];
		int[] maxsL = new int[n+2];
		int[] maxsR = new int[n+2];
		int[] minsR = new int[n+2];
		int[] kawase = new int[n+2];

		minsL[0] = Integer.MAX_VALUE;
		maxsL[0] = 0;
		for(int i=1;i<=n;i++) {
			kawase[i] = in.nextInt();
			minsL[i] = Math.min(minsL[i-1], kawase[i]);
			maxsL[i] = Math.max(maxsL[i-1], kawase[i]);
		}
		minsR[n+1] = Integer.MAX_VALUE;
		maxsR[n+1] = 0;
		for(int i=n;i>=1;i--) {
			minsR[i] = Math.min(minsR[i+1], kawase[i]);
			maxsR[i] = Math.max(maxsR[i+1], kawase[i]);
		}

		int ans = Integer.MIN_VALUE;
		for(int i=1;i<n;i++) {
			ans = Math.max(ans, maxsR[i+1] - minsL[i]);
//			ans = Math.max(ans, Math.abs(maxsL[i] - minsR[i+1]));
		}
		System.out.println(ans);
	}
}