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));
		}
		int cursor = list.size() - 2;
		long maxProfit = list.get(cursor + 1) - list.get(cursor);
		long a, b;
		long max = (a = list.get(cursor + 1)) > (b = list.get(cursor)) ? a : b;
		cursor--;
		while(cursor >= 0){
			if(max - list.get(cursor) > maxProfit){
				maxProfit = max - list.get(cursor);
			}
			if(list.get(cursor) > max){
				max = list.get(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));
		}
		int cursor = list.size() - 2;
		long maxProfit = list.get(cursor + 1) - list.get(cursor);
		long a, b;
		long max = (a = list.get(cursor + 1)) > (b = list.get(cursor)) ? a : b;
		cursor--;
		while(cursor >= 0){
			if(max - list.get(cursor) > maxProfit){
				maxProfit = max - list.get(cursor);
			}
			if(list.get(cursor) > max){
				max = list.get(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));
		}
		int cursor = list.size() - 2;
		long maxProfit = list.get(cursor + 1) - list.get(cursor);
		long a, b;
		long max = (a = list.get(cursor + 1)) > (b = list.get(cursor)) ? a : b;
		cursor--;
		while(cursor >= 0){
			if(max - list.get(cursor) > maxProfit){
				maxProfit = max - list.get(cursor);
			}
			if(list.get(cursor) > max){
				max = list.get(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));
		}
		int cursor = list.size() - 2;
		long maxProfit = list.get(cursor + 1) - list.get(cursor);
		long a, b;
		long max = (a = list.get(cursor + 1)) > (b = list.get(cursor)) ? a : b;
		cursor--;
		while(cursor >= 0){
			if(max - list.get(cursor) > maxProfit){
				maxProfit = max - list.get(cursor);
			}
			if(list.get(cursor) > max){
				max = list.get(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 int cursor = list.size() - 2; cursor list.size() - 2 list.size() list.size list 2 long maxProfit = list.get(cursor + 1) - list.get(cursor); maxProfit list.get(cursor + 1) - list.get(cursor) list.get(cursor + 1) list.get list cursor + 1 cursor 1 list.get(cursor) list.get list cursor long a a b; b long max = (a = list.get(cursor + 1)) > (b = list.get(cursor)) ? a : b; max (a = list.get(cursor + 1)) > (b = list.get(cursor)) ? a : b (a = list.get(cursor + 1)) > (b = list.get(cursor)) (a = list.get(cursor + 1)) a list.get(cursor + 1) list.get list cursor + 1 cursor 1 (b = list.get(cursor)) b list.get(cursor) list.get list cursor a b cursor-- cursor while(cursor >= 0){
			if(max - list.get(cursor) > maxProfit){
				maxProfit = max - list.get(cursor);
			}
			if(list.get(cursor) > max){
				max = list.get(cursor);
			}
			cursor--;
		} cursor >= 0 cursor 0 {
			if(max - list.get(cursor) > maxProfit){
				maxProfit = max - list.get(cursor);
			}
			if(list.get(cursor) > max){
				max = list.get(cursor);
			}
			cursor--;
		} if(max - list.get(cursor) > maxProfit){
				maxProfit = max - list.get(cursor);
			} max - list.get(cursor) > maxProfit max - list.get(cursor) max list.get(cursor) list.get list cursor maxProfit {
				maxProfit = max - list.get(cursor);
			} maxProfit = max - list.get(cursor) maxProfit max - list.get(cursor) max list.get(cursor) list.get list cursor if(list.get(cursor) > max){
				max = list.get(cursor);
			} list.get(cursor) > max list.get(cursor) list.get list cursor max {
				max = list.get(cursor);
			} max = list.get(cursor) max list.get(cursor) list.get list 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));
		}
		int cursor = list.size() - 2;
		long maxProfit = list.get(cursor + 1) - list.get(cursor);
		long a, b;
		long max = (a = list.get(cursor + 1)) > (b = list.get(cursor)) ? a : b;
		cursor--;
		while(cursor >= 0){
			if(max - list.get(cursor) > maxProfit){
				maxProfit = max - list.get(cursor);
			}
			if(list.get(cursor) > max){
				max = list.get(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));
		}
		int cursor = list.size() - 2;
		long maxProfit = list.get(cursor + 1) - list.get(cursor);
		long a, b;
		long max = (a = list.get(cursor + 1)) > (b = list.get(cursor)) ? a : b;
		cursor--;
		while(cursor >= 0){
			if(max - list.get(cursor) > maxProfit){
				maxProfit = max - list.get(cursor);
			}
			if(list.get(cursor) > max){
				max = list.get(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));
		}
		int cursor = list.size() - 2;
		long maxProfit = list.get(cursor + 1) - list.get(cursor);
		long a, b;
		long max = (a = list.get(cursor + 1)) > (b = list.get(cursor)) ? a : b;
		cursor--;
		while(cursor >= 0){
			if(max - list.get(cursor) > maxProfit){
				maxProfit = max - list.get(cursor);
			}
			if(list.get(cursor) > max){
				max = list.get(cursor);
			}
			cursor--;
		}
		System.out.println(maxProfit);
	}
}