import java.util.Scanner;

public class Main {
	
	static Scanner scan;
	
	public static void main(String[] main) {
		scan = new Scanner(System.in);
		
		// Get the input number of array's elements.
		final int n = scan.nextInt();
		
		// Get the input array.
		int list[] = new int[n];
		for(int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		}
		
		// Calculate the max profit.
		int max = list[1] - list[0];
		int key = list[0];
		for(int i = 0; i < n-1; i++) {
			for(int j = i+1; j < n; j++) {
				if(key < list[i]) break;
				if(max < list[j] - list[i]) {
					max = list[j] - list[i];
					key = list[i];
				}
			}
		}

		// Output the result.
		System.out.println(max);
	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	
	static Scanner scan;
	
	public static void main(String[] main) {
		scan = new Scanner(System.in);
		
		// Get the input number of array's elements.
		final int n = scan.nextInt();
		
		// Get the input array.
		int list[] = new int[n];
		for(int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		}
		
		// Calculate the max profit.
		int max = list[1] - list[0];
		int key = list[0];
		for(int i = 0; i < n-1; i++) {
			for(int j = i+1; j < n; j++) {
				if(key < list[i]) break;
				if(max < list[j] - list[i]) {
					max = list[j] - list[i];
					key = list[i];
				}
			}
		}

		// Output the result.
		System.out.println(max);
	}
} Main static Scanner scan; scan public static void main(String[] main) {
		scan = new Scanner(System.in);
		
		// Get the input number of array's elements.
		final int n = scan.nextInt();
		
		// Get the input array.
		int list[] = new int[n];
		for(int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		}
		
		// Calculate the max profit.
		int max = list[1] - list[0];
		int key = list[0];
		for(int i = 0; i < n-1; i++) {
			for(int j = i+1; j < n; j++) {
				if(key < list[i]) break;
				if(max < list[j] - list[i]) {
					max = list[j] - list[i];
					key = list[i];
				}
			}
		}

		// Output the result.
		System.out.println(max);
	} main {
		scan = new Scanner(System.in);
		
		// Get the input number of array's elements.
		final int n = scan.nextInt();
		
		// Get the input array.
		int list[] = new int[n];
		for(int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		}
		
		// Calculate the max profit.
		int max = list[1] - list[0];
		int key = list[0];
		for(int i = 0; i < n-1; i++) {
			for(int j = i+1; j < n; j++) {
				if(key < list[i]) break;
				if(max < list[j] - list[i]) {
					max = list[j] - list[i];
					key = list[i];
				}
			}
		}

		// Output the result.
		System.out.println(max);
	} scan = new Scanner(System.in) scan new Scanner(System.in) final int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int list[] = new int[n]; list new int[n] n for(int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			list[i] = scan.nextInt();
		} {
			list[i] = scan.nextInt();
		} list[i] = scan.nextInt() list[i] list i scan.nextInt() scan.nextInt scan int max = list[1] - list[0]; max list[1] - list[0] list[1] list 1 list[0] list 0 int key = list[0]; key list[0] list 0 for(int i = 0; i < n-1; i++) {
			for(int j = i+1; j < n; j++) {
				if(key < list[i]) break;
				if(max < list[j] - list[i]) {
					max = list[j] - list[i];
					key = list[i];
				}
			}
		} int i = 0; int i = 0; i 0 i < n-1 i n-1 n 1 i++ i++ i {
			for(int j = i+1; j < n; j++) {
				if(key < list[i]) break;
				if(max < list[j] - list[i]) {
					max = list[j] - list[i];
					key = list[i];
				}
			}
		} {
			for(int j = i+1; j < n; j++) {
				if(key < list[i]) break;
				if(max < list[j] - list[i]) {
					max = list[j] - list[i];
					key = list[i];
				}
			}
		} for(int j = i+1; j < n; j++) {
				if(key < list[i]) break;
				if(max < list[j] - list[i]) {
					max = list[j] - list[i];
					key = list[i];
				}
			} int j = i+1; int j = i+1; j i+1 i 1 j < n j n j++ j++ j {
				if(key < list[i]) break;
				if(max < list[j] - list[i]) {
					max = list[j] - list[i];
					key = list[i];
				}
			} {
				if(key < list[i]) break;
				if(max < list[j] - list[i]) {
					max = list[j] - list[i];
					key = list[i];
				}
			} if(key < list[i]) break; key < list[i] key list[i] list i break; if(max < list[j] - list[i]) {
					max = list[j] - list[i];
					key = list[i];
				} max < list[j] - list[i] max list[j] - list[i] list[j] list j list[i] list i {
					max = list[j] - list[i];
					key = list[i];
				} max = list[j] - list[i] max list[j] - list[i] list[j] list j list[i] list i key = list[i] key list[i] list i System.out.println(max) System.out.println System.out System System.out max String[] main main public class Main {
	
	static Scanner scan;
	
	public static void main(String[] main) {
		scan = new Scanner(System.in);
		
		// Get the input number of array's elements.
		final int n = scan.nextInt();
		
		// Get the input array.
		int list[] = new int[n];
		for(int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		}
		
		// Calculate the max profit.
		int max = list[1] - list[0];
		int key = list[0];
		for(int i = 0; i < n-1; i++) {
			for(int j = i+1; j < n; j++) {
				if(key < list[i]) break;
				if(max < list[j] - list[i]) {
					max = list[j] - list[i];
					key = list[i];
				}
			}
		}

		// Output the result.
		System.out.println(max);
	}
} public class Main {
	
	static Scanner scan;
	
	public static void main(String[] main) {
		scan = new Scanner(System.in);
		
		// Get the input number of array's elements.
		final int n = scan.nextInt();
		
		// Get the input array.
		int list[] = new int[n];
		for(int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		}
		
		// Calculate the max profit.
		int max = list[1] - list[0];
		int key = list[0];
		for(int i = 0; i < n-1; i++) {
			for(int j = i+1; j < n; j++) {
				if(key < list[i]) break;
				if(max < list[j] - list[i]) {
					max = list[j] - list[i];
					key = list[i];
				}
			}
		}

		// Output the result.
		System.out.println(max);
	}
} Main
import java.util.Scanner;

public class Main {
	
	static Scanner scan;
	
	public static void main(String[] main) {
		scan = new Scanner(System.in);
		
		// Get the input number of array's elements.
		final int n = scan.nextInt();
		
		// Get the input array.
		int list[] = new int[n];
		for(int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		}
		
		// Calculate the max profit.
		int max = list[1] - list[0];
		int key = list[0];
		for(int i = 0; i < n-1; i++) {
			for(int j = i+1; j < n; j++) {
				if(key < list[i]) break;
				if(max < list[j] - list[i]) {
					max = list[j] - list[i];
					key = list[i];
				}
			}
		}

		// Output the result.
		System.out.println(max);
	}
}

