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

public class Main {
	public static void main(String[] args) {
		final int[] list = getList();
		final int diff = getMaxDiff(list);
		
		System.out.println(diff);
	}
	
	public static int getMaxDiff(int[] list) {
        int maxDiff = list[1] - list[0];
        int min = list[0];
        
        int diff;
        for (int i = 2; i < list.length; i++) {
        	if (list[i-1] < min) min = list[i-1];
        	diff = list[i] - min;
        	if (maxDiff < diff) maxDiff = diff;
        }
         
        return maxDiff;
    }
	
	public static int[] getList() {
		int[] list = null;
		
		try {
			final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			final int n = Integer.parseInt(reader.readLine());
			list = new int[n];
			for (int i = 0; i < n; i++) {
				list[i] = Integer.parseInt(reader.readLine());
			}
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) {
		final int[] list = getList();
		final int diff = getMaxDiff(list);
		
		System.out.println(diff);
	}
	
	public static int getMaxDiff(int[] list) {
        int maxDiff = list[1] - list[0];
        int min = list[0];
        
        int diff;
        for (int i = 2; i < list.length; i++) {
        	if (list[i-1] < min) min = list[i-1];
        	diff = list[i] - min;
        	if (maxDiff < diff) maxDiff = diff;
        }
         
        return maxDiff;
    }
	
	public static int[] getList() {
		int[] list = null;
		
		try {
			final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			final int n = Integer.parseInt(reader.readLine());
			list = new int[n];
			for (int i = 0; i < n; i++) {
				list[i] = Integer.parseInt(reader.readLine());
			}
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
	}
} Main public static void main(String[] args) {
		final int[] list = getList();
		final int diff = getMaxDiff(list);
		
		System.out.println(diff);
	} main {
		final int[] list = getList();
		final int diff = getMaxDiff(list);
		
		System.out.println(diff);
	} final int[] list = getList(); list getList() getList final int diff = getMaxDiff(list); diff getMaxDiff(list) getMaxDiff list System.out.println(diff) System.out.println System.out System System.out diff String[] args args public static int getMaxDiff(int[] list) {
        int maxDiff = list[1] - list[0];
        int min = list[0];
        
        int diff;
        for (int i = 2; i < list.length; i++) {
        	if (list[i-1] < min) min = list[i-1];
        	diff = list[i] - min;
        	if (maxDiff < diff) maxDiff = diff;
        }
         
        return maxDiff;
    } getMaxDiff {
        int maxDiff = list[1] - list[0];
        int min = list[0];
        
        int diff;
        for (int i = 2; i < list.length; i++) {
        	if (list[i-1] < min) min = list[i-1];
        	diff = list[i] - min;
        	if (maxDiff < diff) maxDiff = diff;
        }
         
        return maxDiff;
    } int maxDiff = list[1] - list[0]; maxDiff list[1] - list[0] list[1] list 1 list[0] list 0 int min = list[0]; min list[0] list 0 int diff; diff for (int i = 2; i < list.length; i++) {
        	if (list[i-1] < min) min = list[i-1];
        	diff = list[i] - min;
        	if (maxDiff < diff) maxDiff = diff;
        } int i = 2; int i = 2; i 2 i < list.length i list.length list list.length i++ i++ i {
        	if (list[i-1] < min) min = list[i-1];
        	diff = list[i] - min;
        	if (maxDiff < diff) maxDiff = diff;
        } {
        	if (list[i-1] < min) min = list[i-1];
        	diff = list[i] - min;
        	if (maxDiff < diff) maxDiff = diff;
        } if (list[i-1] < min) min = list[i-1]; list[i-1] < min list[i-1] list i-1 i 1 min min = list[i-1] min list[i-1] list i-1 i 1 diff = list[i] - min diff list[i] - min list[i] list i min if (maxDiff < diff) maxDiff = diff; maxDiff < diff maxDiff diff maxDiff = diff maxDiff diff return maxDiff; maxDiff int[] list list public static int[] getList() {
		int[] list = null;
		
		try {
			final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			final int n = Integer.parseInt(reader.readLine());
			list = new int[n];
			for (int i = 0; i < n; i++) {
				list[i] = Integer.parseInt(reader.readLine());
			}
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
	} getList {
		int[] list = null;
		
		try {
			final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			final int n = Integer.parseInt(reader.readLine());
			list = new int[n];
			for (int i = 0; i < n; i++) {
				list[i] = Integer.parseInt(reader.readLine());
			}
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
	} int[] list = null; list null try {
			final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			final int n = Integer.parseInt(reader.readLine());
			list = new int[n];
			for (int i = 0; i < n; i++) {
				list[i] = Integer.parseInt(reader.readLine());
			}
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} Exception e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			final int n = Integer.parseInt(reader.readLine());
			list = new int[n];
			for (int i = 0; i < n; i++) {
				list[i] = Integer.parseInt(reader.readLine());
			}
			reader.close();
		} final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) final int n = Integer.parseInt(reader.readLine()); n Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader list = new int[n] list new int[n] n for (int i = 0; i < n; i++) {
				list[i] = Integer.parseInt(reader.readLine());
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				list[i] = Integer.parseInt(reader.readLine());
			} {
				list[i] = Integer.parseInt(reader.readLine());
			} list[i] = Integer.parseInt(reader.readLine()) list[i] list i Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader reader.close() reader.close reader return list; list public class Main {
	public static void main(String[] args) {
		final int[] list = getList();
		final int diff = getMaxDiff(list);
		
		System.out.println(diff);
	}
	
	public static int getMaxDiff(int[] list) {
        int maxDiff = list[1] - list[0];
        int min = list[0];
        
        int diff;
        for (int i = 2; i < list.length; i++) {
        	if (list[i-1] < min) min = list[i-1];
        	diff = list[i] - min;
        	if (maxDiff < diff) maxDiff = diff;
        }
         
        return maxDiff;
    }
	
	public static int[] getList() {
		int[] list = null;
		
		try {
			final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			final int n = Integer.parseInt(reader.readLine());
			list = new int[n];
			for (int i = 0; i < n; i++) {
				list[i] = Integer.parseInt(reader.readLine());
			}
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
	}
} public class Main {
	public static void main(String[] args) {
		final int[] list = getList();
		final int diff = getMaxDiff(list);
		
		System.out.println(diff);
	}
	
	public static int getMaxDiff(int[] list) {
        int maxDiff = list[1] - list[0];
        int min = list[0];
        
        int diff;
        for (int i = 2; i < list.length; i++) {
        	if (list[i-1] < min) min = list[i-1];
        	diff = list[i] - min;
        	if (maxDiff < diff) maxDiff = diff;
        }
         
        return maxDiff;
    }
	
	public static int[] getList() {
		int[] list = null;
		
		try {
			final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			final int n = Integer.parseInt(reader.readLine());
			list = new int[n];
			for (int i = 0; i < n; i++) {
				list[i] = Integer.parseInt(reader.readLine());
			}
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		final int[] list = getList();
		final int diff = getMaxDiff(list);
		
		System.out.println(diff);
	}
	
	public static int getMaxDiff(int[] list) {
        int maxDiff = list[1] - list[0];
        int min = list[0];
        
        int diff;
        for (int i = 2; i < list.length; i++) {
        	if (list[i-1] < min) min = list[i-1];
        	diff = list[i] - min;
        	if (maxDiff < diff) maxDiff = diff;
        }
         
        return maxDiff;
    }
	
	public static int[] getList() {
		int[] list = null;
		
		try {
			final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			final int n = Integer.parseInt(reader.readLine());
			list = new int[n];
			for (int i = 0; i < n; i++) {
				list[i] = Integer.parseInt(reader.readLine());
			}
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
	}
}