import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int minR = 0;
        int maxDiff = -1000000000;
        for (int i = 0; i < n; i++) {
            int r = scanner.nextInt();
            if (i == 0) {
                minR = r;
                continue;
            }
            int diff = r - minR;
            if (maxDiff < diff) {
                maxDiff = diff;
            }
            if (r < minR) {
                minR = r;
            }
        }
        System.out.println(maxDiff);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int minR = 0;
        int maxDiff = -1000000000;
        for (int i = 0; i < n; i++) {
            int r = scanner.nextInt();
            if (i == 0) {
                minR = r;
                continue;
            }
            int diff = r - minR;
            if (maxDiff < diff) {
                maxDiff = diff;
            }
            if (r < minR) {
                minR = r;
            }
        }
        System.out.println(maxDiff);
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int minR = 0;
        int maxDiff = -1000000000;
        for (int i = 0; i < n; i++) {
            int r = scanner.nextInt();
            if (i == 0) {
                minR = r;
                continue;
            }
            int diff = r - minR;
            if (maxDiff < diff) {
                maxDiff = diff;
            }
            if (r < minR) {
                minR = r;
            }
        }
        System.out.println(maxDiff);
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int minR = 0;
        int maxDiff = -1000000000;
        for (int i = 0; i < n; i++) {
            int r = scanner.nextInt();
            if (i == 0) {
                minR = r;
                continue;
            }
            int diff = r - minR;
            if (maxDiff < diff) {
                maxDiff = diff;
            }
            if (r < minR) {
                minR = r;
            }
        }
        System.out.println(maxDiff);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int minR = 0; minR 0 int maxDiff = -1000000000; maxDiff -1000000000 1000000000 for (int i = 0; i < n; i++) {
            int r = scanner.nextInt();
            if (i == 0) {
                minR = r;
                continue;
            }
            int diff = r - minR;
            if (maxDiff < diff) {
                maxDiff = diff;
            }
            if (r < minR) {
                minR = r;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int r = scanner.nextInt();
            if (i == 0) {
                minR = r;
                continue;
            }
            int diff = r - minR;
            if (maxDiff < diff) {
                maxDiff = diff;
            }
            if (r < minR) {
                minR = r;
            }
        } {
            int r = scanner.nextInt();
            if (i == 0) {
                minR = r;
                continue;
            }
            int diff = r - minR;
            if (maxDiff < diff) {
                maxDiff = diff;
            }
            if (r < minR) {
                minR = r;
            }
        } int r = scanner.nextInt(); r scanner.nextInt() scanner.nextInt scanner if (i == 0) {
                minR = r;
                continue;
            } i == 0 i 0 {
                minR = r;
                continue;
            } minR = r minR r continue; int diff = r - minR; diff r - minR r minR if (maxDiff < diff) {
                maxDiff = diff;
            } maxDiff < diff maxDiff diff {
                maxDiff = diff;
            } maxDiff = diff maxDiff diff if (r < minR) {
                minR = r;
            } r < minR r minR {
                minR = r;
            } minR = r minR r System.out.println(maxDiff) System.out.println System.out System System.out maxDiff String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int minR = 0;
        int maxDiff = -1000000000;
        for (int i = 0; i < n; i++) {
            int r = scanner.nextInt();
            if (i == 0) {
                minR = r;
                continue;
            }
            int diff = r - minR;
            if (maxDiff < diff) {
                maxDiff = diff;
            }
            if (r < minR) {
                minR = r;
            }
        }
        System.out.println(maxDiff);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int minR = 0;
        int maxDiff = -1000000000;
        for (int i = 0; i < n; i++) {
            int r = scanner.nextInt();
            if (i == 0) {
                minR = r;
                continue;
            }
            int diff = r - minR;
            if (maxDiff < diff) {
                maxDiff = diff;
            }
            if (r < minR) {
                minR = r;
            }
        }
        System.out.println(maxDiff);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int minR = 0;
        int maxDiff = -1000000000;
        for (int i = 0; i < n; i++) {
            int r = scanner.nextInt();
            if (i == 0) {
                minR = r;
                continue;
            }
            int diff = r - minR;
            if (maxDiff < diff) {
                maxDiff = diff;
            }
            if (r < minR) {
                minR = r;
            }
        }
        System.out.println(maxDiff);
    }
}