import java.util.Scanner;
public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	int[] r = new int[n];
	for (int i = 0; i < n; i++) {
	    r[i] = Integer.parseInt(scan.nextLine());
	}
	int max = r[1] - r[0];
	int min = r[0];
	for (int i = 1; i < n; i++) {
	    if (max < r[i] - min){
		max = r[i] - min;
	    }
	    if (min > r[i]){
		min = r[i];
	    }
	}
	System.out.println(max);
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	int[] r = new int[n];
	for (int i = 0; i < n; i++) {
	    r[i] = Integer.parseInt(scan.nextLine());
	}
	int max = r[1] - r[0];
	int min = r[0];
	for (int i = 1; i < n; i++) {
	    if (max < r[i] - min){
		max = r[i] - min;
	    }
	    if (min > r[i]){
		min = r[i];
	    }
	}
	System.out.println(max);
    }
} Main public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	int[] r = new int[n];
	for (int i = 0; i < n; i++) {
	    r[i] = Integer.parseInt(scan.nextLine());
	}
	int max = r[1] - r[0];
	int min = r[0];
	for (int i = 1; i < n; i++) {
	    if (max < r[i] - min){
		max = r[i] - min;
	    }
	    if (min > r[i]){
		min = r[i];
	    }
	}
	System.out.println(max);
    } main {
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	int[] r = new int[n];
	for (int i = 0; i < n; i++) {
	    r[i] = Integer.parseInt(scan.nextLine());
	}
	int max = r[1] - r[0];
	int min = r[0];
	for (int i = 1; i < n; i++) {
	    if (max < r[i] - min){
		max = r[i] - min;
	    }
	    if (min > r[i]){
		min = r[i];
	    }
	}
	System.out.println(max);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = Integer.parseInt(scan.nextLine()); n Integer.parseInt(scan.nextLine()) Integer.parseInt Integer scan.nextLine() scan.nextLine scan int[] r = new int[n]; r new int[n] n for (int i = 0; i < n; i++) {
	    r[i] = Integer.parseInt(scan.nextLine());
	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
	    r[i] = Integer.parseInt(scan.nextLine());
	} {
	    r[i] = Integer.parseInt(scan.nextLine());
	} r[i] = Integer.parseInt(scan.nextLine()) r[i] r i Integer.parseInt(scan.nextLine()) Integer.parseInt Integer scan.nextLine() scan.nextLine scan int max = r[1] - r[0]; max r[1] - r[0] r[1] r 1 r[0] r 0 int min = r[0]; min r[0] r 0 for (int i = 1; i < n; i++) {
	    if (max < r[i] - min){
		max = r[i] - min;
	    }
	    if (min > r[i]){
		min = r[i];
	    }
	} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
	    if (max < r[i] - min){
		max = r[i] - min;
	    }
	    if (min > r[i]){
		min = r[i];
	    }
	} {
	    if (max < r[i] - min){
		max = r[i] - min;
	    }
	    if (min > r[i]){
		min = r[i];
	    }
	} if (max < r[i] - min){
		max = r[i] - min;
	    } max < r[i] - min max r[i] - min r[i] r i min {
		max = r[i] - min;
	    } max = r[i] - min max r[i] - min r[i] r i min if (min > r[i]){
		min = r[i];
	    } min > r[i] min r[i] r i {
		min = r[i];
	    } min = r[i] min r[i] r i System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	int[] r = new int[n];
	for (int i = 0; i < n; i++) {
	    r[i] = Integer.parseInt(scan.nextLine());
	}
	int max = r[1] - r[0];
	int min = r[0];
	for (int i = 1; i < n; i++) {
	    if (max < r[i] - min){
		max = r[i] - min;
	    }
	    if (min > r[i]){
		min = r[i];
	    }
	}
	System.out.println(max);
    }
} public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	int[] r = new int[n];
	for (int i = 0; i < n; i++) {
	    r[i] = Integer.parseInt(scan.nextLine());
	}
	int max = r[1] - r[0];
	int min = r[0];
	for (int i = 1; i < n; i++) {
	    if (max < r[i] - min){
		max = r[i] - min;
	    }
	    if (min > r[i]){
		min = r[i];
	    }
	}
	System.out.println(max);
    }
} Main
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	int[] r = new int[n];
	for (int i = 0; i < n; i++) {
	    r[i] = Integer.parseInt(scan.nextLine());
	}
	int max = r[1] - r[0];
	int min = r[0];
	for (int i = 1; i < n; i++) {
	    if (max < r[i] - min){
		max = r[i] - min;
	    }
	    if (min > r[i]){
		min = r[i];
	    }
	}
	System.out.println(max);
    }
}