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

public class Main {
	
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public static String[] readStandartInput() throws IOException{
		String str = br.readLine();
		String[] list = str.split(" ");
		
		return list;
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.valueOf(readStandartInput()[0]);
		List<Integer> list = new ArrayList<>();
		
		for(int i = 0; i < n; i++){
			int a = Integer.valueOf(readStandartInput()[0]);
			list.add(a);
		}
		
		
		int old = list.get(0);
		int max = old;
		int min = old;
		int maxBenefit = 0;
		int maxDelta = Integer.MIN_VALUE;
		
		for(int i = 1; i < list.size(); i++){
			int r = list.get(i);
			int delta = r - old;
			if(maxDelta < delta){
				maxDelta = delta;
			}
			if(r < min){
				min = r;
				max = r;
			}else if(max < r){
				max = r;
				int benefit = max - min;
				if(maxBenefit < benefit){
					maxBenefit = benefit;
				}
			}
			old = r;
		}
		if(maxBenefit == 0){
			maxBenefit = maxDelta;
		}
		
		System.out.println(maxBenefit);
		
		
	}
	
}
 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 {
	
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public static String[] readStandartInput() throws IOException{
		String str = br.readLine();
		String[] list = str.split(" ");
		
		return list;
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.valueOf(readStandartInput()[0]);
		List<Integer> list = new ArrayList<>();
		
		for(int i = 0; i < n; i++){
			int a = Integer.valueOf(readStandartInput()[0]);
			list.add(a);
		}
		
		
		int old = list.get(0);
		int max = old;
		int min = old;
		int maxBenefit = 0;
		int maxDelta = Integer.MIN_VALUE;
		
		for(int i = 1; i < list.size(); i++){
			int r = list.get(i);
			int delta = r - old;
			if(maxDelta < delta){
				maxDelta = delta;
			}
			if(r < min){
				min = r;
				max = r;
			}else if(max < r){
				max = r;
				int benefit = max - min;
				if(maxBenefit < benefit){
					maxBenefit = benefit;
				}
			}
			old = r;
		}
		if(maxBenefit == 0){
			maxBenefit = maxDelta;
		}
		
		System.out.println(maxBenefit);
		
		
	}
	
} Main private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) public static String[] readStandartInput() throws IOException{
		String str = br.readLine();
		String[] list = str.split(" ");
		
		return list;
	} readStandartInput {
		String str = br.readLine();
		String[] list = str.split(" ");
		
		return list;
	} String str = br.readLine(); str br.readLine() br.readLine br String[] list = str.split(" "); list str.split(" ") str.split str " " return list; list public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.valueOf(readStandartInput()[0]);
		List<Integer> list = new ArrayList<>();
		
		for(int i = 0; i < n; i++){
			int a = Integer.valueOf(readStandartInput()[0]);
			list.add(a);
		}
		
		
		int old = list.get(0);
		int max = old;
		int min = old;
		int maxBenefit = 0;
		int maxDelta = Integer.MIN_VALUE;
		
		for(int i = 1; i < list.size(); i++){
			int r = list.get(i);
			int delta = r - old;
			if(maxDelta < delta){
				maxDelta = delta;
			}
			if(r < min){
				min = r;
				max = r;
			}else if(max < r){
				max = r;
				int benefit = max - min;
				if(maxBenefit < benefit){
					maxBenefit = benefit;
				}
			}
			old = r;
		}
		if(maxBenefit == 0){
			maxBenefit = maxDelta;
		}
		
		System.out.println(maxBenefit);
		
		
	} main {
		int n = Integer.valueOf(readStandartInput()[0]);
		List<Integer> list = new ArrayList<>();
		
		for(int i = 0; i < n; i++){
			int a = Integer.valueOf(readStandartInput()[0]);
			list.add(a);
		}
		
		
		int old = list.get(0);
		int max = old;
		int min = old;
		int maxBenefit = 0;
		int maxDelta = Integer.MIN_VALUE;
		
		for(int i = 1; i < list.size(); i++){
			int r = list.get(i);
			int delta = r - old;
			if(maxDelta < delta){
				maxDelta = delta;
			}
			if(r < min){
				min = r;
				max = r;
			}else if(max < r){
				max = r;
				int benefit = max - min;
				if(maxBenefit < benefit){
					maxBenefit = benefit;
				}
			}
			old = r;
		}
		if(maxBenefit == 0){
			maxBenefit = maxDelta;
		}
		
		System.out.println(maxBenefit);
		
		
	} int n = Integer.valueOf(readStandartInput()[0]); n Integer.valueOf(readStandartInput()[0]) Integer.valueOf Integer readStandartInput()[0] readStandartInput() readStandartInput 0 List<Integer> list = new ArrayList<>(); list new ArrayList<>() for(int i = 0; i < n; i++){
			int a = Integer.valueOf(readStandartInput()[0]);
			list.add(a);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int a = Integer.valueOf(readStandartInput()[0]);
			list.add(a);
		} {
			int a = Integer.valueOf(readStandartInput()[0]);
			list.add(a);
		} int a = Integer.valueOf(readStandartInput()[0]); a Integer.valueOf(readStandartInput()[0]) Integer.valueOf Integer readStandartInput()[0] readStandartInput() readStandartInput 0 list.add(a) list.add list a int old = list.get(0); old list.get(0) list.get list 0 int max = old; max old int min = old; min old int maxBenefit = 0; maxBenefit 0 int maxDelta = Integer.MIN_VALUE; maxDelta Integer.MIN_VALUE Integer Integer.MIN_VALUE for(int i = 1; i < list.size(); i++){
			int r = list.get(i);
			int delta = r - old;
			if(maxDelta < delta){
				maxDelta = delta;
			}
			if(r < min){
				min = r;
				max = r;
			}else if(max < r){
				max = r;
				int benefit = max - min;
				if(maxBenefit < benefit){
					maxBenefit = benefit;
				}
			}
			old = r;
		} int i = 1; int i = 1; i 1 i < list.size() i list.size() list.size list i++ i++ i {
			int r = list.get(i);
			int delta = r - old;
			if(maxDelta < delta){
				maxDelta = delta;
			}
			if(r < min){
				min = r;
				max = r;
			}else if(max < r){
				max = r;
				int benefit = max - min;
				if(maxBenefit < benefit){
					maxBenefit = benefit;
				}
			}
			old = r;
		} {
			int r = list.get(i);
			int delta = r - old;
			if(maxDelta < delta){
				maxDelta = delta;
			}
			if(r < min){
				min = r;
				max = r;
			}else if(max < r){
				max = r;
				int benefit = max - min;
				if(maxBenefit < benefit){
					maxBenefit = benefit;
				}
			}
			old = r;
		} int r = list.get(i); r list.get(i) list.get list i int delta = r - old; delta r - old r old if(maxDelta < delta){
				maxDelta = delta;
			} maxDelta < delta maxDelta delta {
				maxDelta = delta;
			} maxDelta = delta maxDelta delta if(r < min){
				min = r;
				max = r;
			}else if(max < r){
				max = r;
				int benefit = max - min;
				if(maxBenefit < benefit){
					maxBenefit = benefit;
				}
			} r < min r min {
				min = r;
				max = r;
			} min = r min r max = r max r if(max < r){
				max = r;
				int benefit = max - min;
				if(maxBenefit < benefit){
					maxBenefit = benefit;
				}
			} max < r max r {
				max = r;
				int benefit = max - min;
				if(maxBenefit < benefit){
					maxBenefit = benefit;
				}
			} max = r max r int benefit = max - min; benefit max - min max min if(maxBenefit < benefit){
					maxBenefit = benefit;
				} maxBenefit < benefit maxBenefit benefit {
					maxBenefit = benefit;
				} maxBenefit = benefit maxBenefit benefit old = r old r if(maxBenefit == 0){
			maxBenefit = maxDelta;
		} maxBenefit == 0 maxBenefit 0 {
			maxBenefit = maxDelta;
		} maxBenefit = maxDelta maxBenefit maxDelta System.out.println(maxBenefit) System.out.println System.out System System.out maxBenefit String[] args args public class Main {
	
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public static String[] readStandartInput() throws IOException{
		String str = br.readLine();
		String[] list = str.split(" ");
		
		return list;
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.valueOf(readStandartInput()[0]);
		List<Integer> list = new ArrayList<>();
		
		for(int i = 0; i < n; i++){
			int a = Integer.valueOf(readStandartInput()[0]);
			list.add(a);
		}
		
		
		int old = list.get(0);
		int max = old;
		int min = old;
		int maxBenefit = 0;
		int maxDelta = Integer.MIN_VALUE;
		
		for(int i = 1; i < list.size(); i++){
			int r = list.get(i);
			int delta = r - old;
			if(maxDelta < delta){
				maxDelta = delta;
			}
			if(r < min){
				min = r;
				max = r;
			}else if(max < r){
				max = r;
				int benefit = max - min;
				if(maxBenefit < benefit){
					maxBenefit = benefit;
				}
			}
			old = r;
		}
		if(maxBenefit == 0){
			maxBenefit = maxDelta;
		}
		
		System.out.println(maxBenefit);
		
		
	}
	
} public class Main {
	
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public static String[] readStandartInput() throws IOException{
		String str = br.readLine();
		String[] list = str.split(" ");
		
		return list;
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.valueOf(readStandartInput()[0]);
		List<Integer> list = new ArrayList<>();
		
		for(int i = 0; i < n; i++){
			int a = Integer.valueOf(readStandartInput()[0]);
			list.add(a);
		}
		
		
		int old = list.get(0);
		int max = old;
		int min = old;
		int maxBenefit = 0;
		int maxDelta = Integer.MIN_VALUE;
		
		for(int i = 1; i < list.size(); i++){
			int r = list.get(i);
			int delta = r - old;
			if(maxDelta < delta){
				maxDelta = delta;
			}
			if(r < min){
				min = r;
				max = r;
			}else if(max < r){
				max = r;
				int benefit = max - min;
				if(maxBenefit < benefit){
					maxBenefit = benefit;
				}
			}
			old = r;
		}
		if(maxBenefit == 0){
			maxBenefit = maxDelta;
		}
		
		System.out.println(maxBenefit);
		
		
	}
	
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public static String[] readStandartInput() throws IOException{
		String str = br.readLine();
		String[] list = str.split(" ");
		
		return list;
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.valueOf(readStandartInput()[0]);
		List<Integer> list = new ArrayList<>();
		
		for(int i = 0; i < n; i++){
			int a = Integer.valueOf(readStandartInput()[0]);
			list.add(a);
		}
		
		
		int old = list.get(0);
		int max = old;
		int min = old;
		int maxBenefit = 0;
		int maxDelta = Integer.MIN_VALUE;
		
		for(int i = 1; i < list.size(); i++){
			int r = list.get(i);
			int delta = r - old;
			if(maxDelta < delta){
				maxDelta = delta;
			}
			if(r < min){
				min = r;
				max = r;
			}else if(max < r){
				max = r;
				int benefit = max - min;
				if(maxBenefit < benefit){
					maxBenefit = benefit;
				}
			}
			old = r;
		}
		if(maxBenefit == 0){
			maxBenefit = maxDelta;
		}
		
		System.out.println(maxBenefit);
		
		
	}
	
}

