import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<Long> list = new ArrayList<Long>(); 
		br.readLine();
		String str;
		while((str = br.readLine()) != null){
			list.add(Long.valueOf(str));
		}
		Long[] arr = new Long[list.size()];
		arr = list.toArray(arr);
		int cursor = arr.length - 2;
		long maxProfit = arr[cursor + 1] - arr[cursor];
		long a, b;
		long max = (a = arr[cursor + 1]) > (b = arr[cursor]) ? a : b;
		cursor--;
		while(cursor >= 0){
			if(max - arr[cursor] > maxProfit){
				maxProfit = max - arr[cursor];
			}
			if(arr[cursor] > max){
				max = arr[cursor];
			}
			cursor--;
		}
		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 import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<Long> list = new ArrayList<Long>(); 
		br.readLine();
		String str;
		while((str = br.readLine()) != null){
			list.add(Long.valueOf(str));
		}
		Long[] arr = new Long[list.size()];
		arr = list.toArray(arr);
		int cursor = arr.length - 2;
		long maxProfit = arr[cursor + 1] - arr[cursor];
		long a, b;
		long max = (a = arr[cursor + 1]) > (b = arr[cursor]) ? a : b;
		cursor--;
		while(cursor >= 0){
			if(max - arr[cursor] > maxProfit){
				maxProfit = max - arr[cursor];
			}
			if(arr[cursor] > max){
				max = arr[cursor];
			}
			cursor--;
		}
		System.out.println(maxProfit);
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<Long> list = new ArrayList<Long>(); 
		br.readLine();
		String str;
		while((str = br.readLine()) != null){
			list.add(Long.valueOf(str));
		}
		Long[] arr = new Long[list.size()];
		arr = list.toArray(arr);
		int cursor = arr.length - 2;
		long maxProfit = arr[cursor + 1] - arr[cursor];
		long a, b;
		long max = (a = arr[cursor + 1]) > (b = arr[cursor]) ? a : b;
		cursor--;
		while(cursor >= 0){
			if(max - arr[cursor] > maxProfit){
				maxProfit = max - arr[cursor];
			}
			if(arr[cursor] > max){
				max = arr[cursor];
			}
			cursor--;
		}
		System.out.println(maxProfit);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<Long> list = new ArrayList<Long>(); 
		br.readLine();
		String str;
		while((str = br.readLine()) != null){
			list.add(Long.valueOf(str));
		}
		Long[] arr = new Long[list.size()];
		arr = list.toArray(arr);
		int cursor = arr.length - 2;
		long maxProfit = arr[cursor + 1] - arr[cursor];
		long a, b;
		long max = (a = arr[cursor + 1]) > (b = arr[cursor]) ? a : b;
		cursor--;
		while(cursor >= 0){
			if(max - arr[cursor] > maxProfit){
				maxProfit = max - arr[cursor];
			}
			if(arr[cursor] > max){
				max = arr[cursor];
			}
			cursor--;
		}
		System.out.println(maxProfit);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) List<Long> list = new ArrayList<Long>(); list new ArrayList<Long>() br.readLine() br.readLine br String str; str while((str = br.readLine()) != null){
			list.add(Long.valueOf(str));
		} (str = br.readLine()) != null (str = br.readLine()) str br.readLine() br.readLine br null {
			list.add(Long.valueOf(str));
		} list.add(Long.valueOf(str)) list.add list Long.valueOf(str) Long.valueOf Long str Long[] arr = new Long[list.size()]; arr new Long[list.size()] list.size() list.size list arr = list.toArray(arr) arr list.toArray(arr) list.toArray list arr int cursor = arr.length - 2; cursor arr.length - 2 arr.length arr arr.length 2 long maxProfit = arr[cursor + 1] - arr[cursor]; maxProfit arr[cursor + 1] - arr[cursor] arr[cursor + 1] arr cursor + 1 cursor 1 arr[cursor] arr cursor long a a b; b long max = (a = arr[cursor + 1]) > (b = arr[cursor]) ? a : b; max (a = arr[cursor + 1]) > (b = arr[cursor]) ? a : b (a = arr[cursor + 1]) > (b = arr[cursor]) (a = arr[cursor + 1]) a arr[cursor + 1] arr cursor + 1 cursor 1 (b = arr[cursor]) b arr[cursor] arr cursor a b cursor-- cursor while(cursor >= 0){
			if(max - arr[cursor] > maxProfit){
				maxProfit = max - arr[cursor];
			}
			if(arr[cursor] > max){
				max = arr[cursor];
			}
			cursor--;
		} cursor >= 0 cursor 0 {
			if(max - arr[cursor] > maxProfit){
				maxProfit = max - arr[cursor];
			}
			if(arr[cursor] > max){
				max = arr[cursor];
			}
			cursor--;
		} if(max - arr[cursor] > maxProfit){
				maxProfit = max - arr[cursor];
			} max - arr[cursor] > maxProfit max - arr[cursor] max arr[cursor] arr cursor maxProfit {
				maxProfit = max - arr[cursor];
			} maxProfit = max - arr[cursor] maxProfit max - arr[cursor] max arr[cursor] arr cursor if(arr[cursor] > max){
				max = arr[cursor];
			} arr[cursor] > max arr[cursor] arr cursor max {
				max = arr[cursor];
			} max = arr[cursor] max arr[cursor] arr cursor cursor-- cursor 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 IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<Long> list = new ArrayList<Long>(); 
		br.readLine();
		String str;
		while((str = br.readLine()) != null){
			list.add(Long.valueOf(str));
		}
		Long[] arr = new Long[list.size()];
		arr = list.toArray(arr);
		int cursor = arr.length - 2;
		long maxProfit = arr[cursor + 1] - arr[cursor];
		long a, b;
		long max = (a = arr[cursor + 1]) > (b = arr[cursor]) ? a : b;
		cursor--;
		while(cursor >= 0){
			if(max - arr[cursor] > maxProfit){
				maxProfit = max - arr[cursor];
			}
			if(arr[cursor] > max){
				max = arr[cursor];
			}
			cursor--;
		}
		System.out.println(maxProfit);
	}
} public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<Long> list = new ArrayList<Long>(); 
		br.readLine();
		String str;
		while((str = br.readLine()) != null){
			list.add(Long.valueOf(str));
		}
		Long[] arr = new Long[list.size()];
		arr = list.toArray(arr);
		int cursor = arr.length - 2;
		long maxProfit = arr[cursor + 1] - arr[cursor];
		long a, b;
		long max = (a = arr[cursor + 1]) > (b = arr[cursor]) ? a : b;
		cursor--;
		while(cursor >= 0){
			if(max - arr[cursor] > maxProfit){
				maxProfit = max - arr[cursor];
			}
			if(arr[cursor] > max){
				max = arr[cursor];
			}
			cursor--;
		}
		System.out.println(maxProfit);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<Long> list = new ArrayList<Long>(); 
		br.readLine();
		String str;
		while((str = br.readLine()) != null){
			list.add(Long.valueOf(str));
		}
		Long[] arr = new Long[list.size()];
		arr = list.toArray(arr);
		int cursor = arr.length - 2;
		long maxProfit = arr[cursor + 1] - arr[cursor];
		long a, b;
		long max = (a = arr[cursor + 1]) > (b = arr[cursor]) ? a : b;
		cursor--;
		while(cursor >= 0){
			if(max - arr[cursor] > maxProfit){
				maxProfit = max - arr[cursor];
			}
			if(arr[cursor] > max){
				max = arr[cursor];
			}
			cursor--;
		}
		System.out.println(maxProfit);
	}
}