

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		//??\?????¨
		int n = Integer.parseInt(br.readLine());

		int[] price = new int[n];
		for(int i = 0; i < n; i++){
			price[i] = Integer.parseInt(br.readLine());
		}

		int maxProfit = Integer.MIN_VALUE;
		int prevBuy = Integer.MAX_VALUE;

		for(int i = 0; i < n - 1; i++){
			int tmpHigh = 0;

			if(price[i] >= prevBuy){
				continue;
			}
			prevBuy = price[i];
			
			for(int j = i + 1; j < n; j++){
				if(price[j] > tmpHigh){
					tmpHigh = price[j];
				}
			}

			if(tmpHigh - price[i] > maxProfit){
				maxProfit = tmpHigh - price[i];
			}
		}


		System.out.println(maxProfit);

	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		//??\?????¨
		int n = Integer.parseInt(br.readLine());

		int[] price = new int[n];
		for(int i = 0; i < n; i++){
			price[i] = Integer.parseInt(br.readLine());
		}

		int maxProfit = Integer.MIN_VALUE;
		int prevBuy = Integer.MAX_VALUE;

		for(int i = 0; i < n - 1; i++){
			int tmpHigh = 0;

			if(price[i] >= prevBuy){
				continue;
			}
			prevBuy = price[i];
			
			for(int j = i + 1; j < n; j++){
				if(price[j] > tmpHigh){
					tmpHigh = price[j];
				}
			}

			if(tmpHigh - price[i] > maxProfit){
				maxProfit = tmpHigh - price[i];
			}
		}


		System.out.println(maxProfit);

	}

} Main public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		//??\?????¨
		int n = Integer.parseInt(br.readLine());

		int[] price = new int[n];
		for(int i = 0; i < n; i++){
			price[i] = Integer.parseInt(br.readLine());
		}

		int maxProfit = Integer.MIN_VALUE;
		int prevBuy = Integer.MAX_VALUE;

		for(int i = 0; i < n - 1; i++){
			int tmpHigh = 0;

			if(price[i] >= prevBuy){
				continue;
			}
			prevBuy = price[i];
			
			for(int j = i + 1; j < n; j++){
				if(price[j] > tmpHigh){
					tmpHigh = price[j];
				}
			}

			if(tmpHigh - price[i] > maxProfit){
				maxProfit = tmpHigh - price[i];
			}
		}


		System.out.println(maxProfit);

	} main {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		//??\?????¨
		int n = Integer.parseInt(br.readLine());

		int[] price = new int[n];
		for(int i = 0; i < n; i++){
			price[i] = Integer.parseInt(br.readLine());
		}

		int maxProfit = Integer.MIN_VALUE;
		int prevBuy = Integer.MAX_VALUE;

		for(int i = 0; i < n - 1; i++){
			int tmpHigh = 0;

			if(price[i] >= prevBuy){
				continue;
			}
			prevBuy = price[i];
			
			for(int j = i + 1; j < n; j++){
				if(price[j] > tmpHigh){
					tmpHigh = price[j];
				}
			}

			if(tmpHigh - price[i] > maxProfit){
				maxProfit = tmpHigh - price[i];
			}
		}


		System.out.println(maxProfit);

	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] price = new int[n]; price new int[n] n for(int i = 0; i < n; i++){
			price[i] = Integer.parseInt(br.readLine());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			price[i] = Integer.parseInt(br.readLine());
		} {
			price[i] = Integer.parseInt(br.readLine());
		} price[i] = Integer.parseInt(br.readLine()) price[i] price i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int maxProfit = Integer.MIN_VALUE; maxProfit Integer.MIN_VALUE Integer Integer.MIN_VALUE int prevBuy = Integer.MAX_VALUE; prevBuy Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i = 0; i < n - 1; i++){
			int tmpHigh = 0;

			if(price[i] >= prevBuy){
				continue;
			}
			prevBuy = price[i];
			
			for(int j = i + 1; j < n; j++){
				if(price[j] > tmpHigh){
					tmpHigh = price[j];
				}
			}

			if(tmpHigh - price[i] > maxProfit){
				maxProfit = tmpHigh - price[i];
			}
		} int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
			int tmpHigh = 0;

			if(price[i] >= prevBuy){
				continue;
			}
			prevBuy = price[i];
			
			for(int j = i + 1; j < n; j++){
				if(price[j] > tmpHigh){
					tmpHigh = price[j];
				}
			}

			if(tmpHigh - price[i] > maxProfit){
				maxProfit = tmpHigh - price[i];
			}
		} {
			int tmpHigh = 0;

			if(price[i] >= prevBuy){
				continue;
			}
			prevBuy = price[i];
			
			for(int j = i + 1; j < n; j++){
				if(price[j] > tmpHigh){
					tmpHigh = price[j];
				}
			}

			if(tmpHigh - price[i] > maxProfit){
				maxProfit = tmpHigh - price[i];
			}
		} int tmpHigh = 0; tmpHigh 0 if(price[i] >= prevBuy){
				continue;
			} price[i] >= prevBuy price[i] price i prevBuy {
				continue;
			} continue; prevBuy = price[i] prevBuy price[i] price i for(int j = i + 1; j < n; j++){
				if(price[j] > tmpHigh){
					tmpHigh = price[j];
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
				if(price[j] > tmpHigh){
					tmpHigh = price[j];
				}
			} {
				if(price[j] > tmpHigh){
					tmpHigh = price[j];
				}
			} if(price[j] > tmpHigh){
					tmpHigh = price[j];
				} price[j] > tmpHigh price[j] price j tmpHigh {
					tmpHigh = price[j];
				} tmpHigh = price[j] tmpHigh price[j] price j if(tmpHigh - price[i] > maxProfit){
				maxProfit = tmpHigh - price[i];
			} tmpHigh - price[i] > maxProfit tmpHigh - price[i] tmpHigh price[i] price i maxProfit {
				maxProfit = tmpHigh - price[i];
			} maxProfit = tmpHigh - price[i] maxProfit tmpHigh - price[i] tmpHigh price[i] price i System.out.println(maxProfit) System.out.println System.out System System.out maxProfit String[] args args public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		//??\?????¨
		int n = Integer.parseInt(br.readLine());

		int[] price = new int[n];
		for(int i = 0; i < n; i++){
			price[i] = Integer.parseInt(br.readLine());
		}

		int maxProfit = Integer.MIN_VALUE;
		int prevBuy = Integer.MAX_VALUE;

		for(int i = 0; i < n - 1; i++){
			int tmpHigh = 0;

			if(price[i] >= prevBuy){
				continue;
			}
			prevBuy = price[i];
			
			for(int j = i + 1; j < n; j++){
				if(price[j] > tmpHigh){
					tmpHigh = price[j];
				}
			}

			if(tmpHigh - price[i] > maxProfit){
				maxProfit = tmpHigh - price[i];
			}
		}


		System.out.println(maxProfit);

	}

} public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		//??\?????¨
		int n = Integer.parseInt(br.readLine());

		int[] price = new int[n];
		for(int i = 0; i < n; i++){
			price[i] = Integer.parseInt(br.readLine());
		}

		int maxProfit = Integer.MIN_VALUE;
		int prevBuy = Integer.MAX_VALUE;

		for(int i = 0; i < n - 1; i++){
			int tmpHigh = 0;

			if(price[i] >= prevBuy){
				continue;
			}
			prevBuy = price[i];
			
			for(int j = i + 1; j < n; j++){
				if(price[j] > tmpHigh){
					tmpHigh = price[j];
				}
			}

			if(tmpHigh - price[i] > maxProfit){
				maxProfit = tmpHigh - price[i];
			}
		}


		System.out.println(maxProfit);

	}

} Main


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		//??\?????¨
		int n = Integer.parseInt(br.readLine());

		int[] price = new int[n];
		for(int i = 0; i < n; i++){
			price[i] = Integer.parseInt(br.readLine());
		}

		int maxProfit = Integer.MIN_VALUE;
		int prevBuy = Integer.MAX_VALUE;

		for(int i = 0; i < n - 1; i++){
			int tmpHigh = 0;

			if(price[i] >= prevBuy){
				continue;
			}
			prevBuy = price[i];
			
			for(int j = i + 1; j < n; j++){
				if(price[j] > tmpHigh){
					tmpHigh = price[j];
				}
			}

			if(tmpHigh - price[i] > maxProfit){
				maxProfit = tmpHigh - price[i];
			}
		}


		System.out.println(maxProfit);

	}

}