import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] r = new int[n];

        int min = 1000000000;


        for(int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        }

        int maxProfit = r[1] - r[0];

        for(int i = 0; i < n - 1; i++) {
            if(r[i] < min) {
                min = r[i];
                for(int j = i + 1; j < n; j++) {
                    int dif = r[j] - r[i];
                    if(dif > maxProfit) maxProfit = dif;
                }
            }
        }

        System.out.println(maxProfit);
    }

} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] r = new int[n];

        int min = 1000000000;


        for(int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        }

        int maxProfit = r[1] - r[0];

        for(int i = 0; i < n - 1; i++) {
            if(r[i] < min) {
                min = r[i];
                for(int j = i + 1; j < n; j++) {
                    int dif = r[j] - r[i];
                    if(dif > maxProfit) maxProfit = dif;
                }
            }
        }

        System.out.println(maxProfit);
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] r = new int[n];

        int min = 1000000000;


        for(int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        }

        int maxProfit = r[1] - r[0];

        for(int i = 0; i < n - 1; i++) {
            if(r[i] < min) {
                min = r[i];
                for(int j = i + 1; j < n; j++) {
                    int dif = r[j] - r[i];
                    if(dif > maxProfit) maxProfit = dif;
                }
            }
        }

        System.out.println(maxProfit);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] r = new int[n];

        int min = 1000000000;


        for(int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        }

        int maxProfit = r[1] - r[0];

        for(int i = 0; i < n - 1; i++) {
            if(r[i] < min) {
                min = r[i];
                for(int j = i + 1; j < n; j++) {
                    int dif = r[j] - r[i];
                    if(dif > maxProfit) maxProfit = dif;
                }
            }
        }

        System.out.println(maxProfit);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] r = new int[n]; r new int[n] n int min = 1000000000; min 1000000000 for(int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            r[i] = sc.nextInt();
        } {
            r[i] = sc.nextInt();
        } r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc int maxProfit = r[1] - r[0]; maxProfit r[1] - r[0] r[1] r 1 r[0] r 0 for(int i = 0; i < n - 1; i++) {
            if(r[i] < min) {
                min = r[i];
                for(int j = i + 1; j < n; j++) {
                    int dif = r[j] - r[i];
                    if(dif > maxProfit) maxProfit = dif;
                }
            }
        } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
            if(r[i] < min) {
                min = r[i];
                for(int j = i + 1; j < n; j++) {
                    int dif = r[j] - r[i];
                    if(dif > maxProfit) maxProfit = dif;
                }
            }
        } {
            if(r[i] < min) {
                min = r[i];
                for(int j = i + 1; j < n; j++) {
                    int dif = r[j] - r[i];
                    if(dif > maxProfit) maxProfit = dif;
                }
            }
        } if(r[i] < min) {
                min = r[i];
                for(int j = i + 1; j < n; j++) {
                    int dif = r[j] - r[i];
                    if(dif > maxProfit) maxProfit = dif;
                }
            } r[i] < min r[i] r i min {
                min = r[i];
                for(int j = i + 1; j < n; j++) {
                    int dif = r[j] - r[i];
                    if(dif > maxProfit) maxProfit = dif;
                }
            } min = r[i] min r[i] r i for(int j = i + 1; j < n; j++) {
                    int dif = r[j] - r[i];
                    if(dif > maxProfit) maxProfit = dif;
                } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
                    int dif = r[j] - r[i];
                    if(dif > maxProfit) maxProfit = dif;
                } {
                    int dif = r[j] - r[i];
                    if(dif > maxProfit) maxProfit = dif;
                } int dif = r[j] - r[i]; dif r[j] - r[i] r[j] r j r[i] r i if(dif > maxProfit) maxProfit = dif; dif > maxProfit dif maxProfit maxProfit = dif maxProfit dif 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) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] r = new int[n];

        int min = 1000000000;


        for(int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        }

        int maxProfit = r[1] - r[0];

        for(int i = 0; i < n - 1; i++) {
            if(r[i] < min) {
                min = r[i];
                for(int j = i + 1; j < n; j++) {
                    int dif = r[j] - r[i];
                    if(dif > maxProfit) maxProfit = dif;
                }
            }
        }

        System.out.println(maxProfit);
    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] r = new int[n];

        int min = 1000000000;


        for(int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        }

        int maxProfit = r[1] - r[0];

        for(int i = 0; i < n - 1; i++) {
            if(r[i] < min) {
                min = r[i];
                for(int j = i + 1; j < n; j++) {
                    int dif = r[j] - r[i];
                    if(dif > maxProfit) maxProfit = dif;
                }
            }
        }

        System.out.println(maxProfit);
    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] r = new int[n];

        int min = 1000000000;


        for(int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        }

        int maxProfit = r[1] - r[0];

        for(int i = 0; i < n - 1; i++) {
            if(r[i] < min) {
                min = r[i];
                for(int j = i + 1; j < n; j++) {
                    int dif = r[j] - r[i];
                    if(dif > maxProfit) maxProfit = dif;
                }
            }
        }

        System.out.println(maxProfit);
    }

}
