import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        int n = Integer.parseInt(scan.nextLine());
        double Rj = 0;
        double Ri = 0;
        double newR;
        double maxProfit = -1000000000;
        double tmpProfit = -1000000000;
        double tmp = 0;

        int value;
        for (int i=0; i<n; i++){
            newR = Integer.parseInt(scan.nextLine());
            if (i == 0){
                Rj = newR;
                Ri = newR;
                continue;
            }
            if (newR < Ri){
                tmp = newR - Ri;
                if (tmp > tmpProfit)
                    tmpProfit = tmp;
                Ri = newR;
                Rj = newR;
                continue;
            }
            if (newR >= Rj){
                Rj = newR;
                tmp = Rj - Ri;
                if (tmp > maxProfit)
                    maxProfit = tmp;
                continue;
            }
        }

        if (tmpProfit > maxProfit)
            maxProfit = tmpProfit;
        else if (tmpProfit == maxProfit)
            maxProfit = 0;

        System.out.println((int)(maxProfit));
    }
} import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        int n = Integer.parseInt(scan.nextLine());
        double Rj = 0;
        double Ri = 0;
        double newR;
        double maxProfit = -1000000000;
        double tmpProfit = -1000000000;
        double tmp = 0;

        int value;
        for (int i=0; i<n; i++){
            newR = Integer.parseInt(scan.nextLine());
            if (i == 0){
                Rj = newR;
                Ri = newR;
                continue;
            }
            if (newR < Ri){
                tmp = newR - Ri;
                if (tmp > tmpProfit)
                    tmpProfit = tmp;
                Ri = newR;
                Rj = newR;
                continue;
            }
            if (newR >= Rj){
                Rj = newR;
                tmp = Rj - Ri;
                if (tmp > maxProfit)
                    maxProfit = tmp;
                continue;
            }
        }

        if (tmpProfit > maxProfit)
            maxProfit = tmpProfit;
        else if (tmpProfit == maxProfit)
            maxProfit = 0;

        System.out.println((int)(maxProfit));
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        int n = Integer.parseInt(scan.nextLine());
        double Rj = 0;
        double Ri = 0;
        double newR;
        double maxProfit = -1000000000;
        double tmpProfit = -1000000000;
        double tmp = 0;

        int value;
        for (int i=0; i<n; i++){
            newR = Integer.parseInt(scan.nextLine());
            if (i == 0){
                Rj = newR;
                Ri = newR;
                continue;
            }
            if (newR < Ri){
                tmp = newR - Ri;
                if (tmp > tmpProfit)
                    tmpProfit = tmp;
                Ri = newR;
                Rj = newR;
                continue;
            }
            if (newR >= Rj){
                Rj = newR;
                tmp = Rj - Ri;
                if (tmp > maxProfit)
                    maxProfit = tmp;
                continue;
            }
        }

        if (tmpProfit > maxProfit)
            maxProfit = tmpProfit;
        else if (tmpProfit == maxProfit)
            maxProfit = 0;

        System.out.println((int)(maxProfit));
    } main {
        Scanner scan = new Scanner(System.in);

        int n = Integer.parseInt(scan.nextLine());
        double Rj = 0;
        double Ri = 0;
        double newR;
        double maxProfit = -1000000000;
        double tmpProfit = -1000000000;
        double tmp = 0;

        int value;
        for (int i=0; i<n; i++){
            newR = Integer.parseInt(scan.nextLine());
            if (i == 0){
                Rj = newR;
                Ri = newR;
                continue;
            }
            if (newR < Ri){
                tmp = newR - Ri;
                if (tmp > tmpProfit)
                    tmpProfit = tmp;
                Ri = newR;
                Rj = newR;
                continue;
            }
            if (newR >= Rj){
                Rj = newR;
                tmp = Rj - Ri;
                if (tmp > maxProfit)
                    maxProfit = tmp;
                continue;
            }
        }

        if (tmpProfit > maxProfit)
            maxProfit = tmpProfit;
        else if (tmpProfit == maxProfit)
            maxProfit = 0;

        System.out.println((int)(maxProfit));
    } 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 double Rj = 0; Rj 0 double Ri = 0; Ri 0 double newR; newR double maxProfit = -1000000000; maxProfit -1000000000 1000000000 double tmpProfit = -1000000000; tmpProfit -1000000000 1000000000 double tmp = 0; tmp 0 int value; value for (int i=0; i<n; i++){
            newR = Integer.parseInt(scan.nextLine());
            if (i == 0){
                Rj = newR;
                Ri = newR;
                continue;
            }
            if (newR < Ri){
                tmp = newR - Ri;
                if (tmp > tmpProfit)
                    tmpProfit = tmp;
                Ri = newR;
                Rj = newR;
                continue;
            }
            if (newR >= Rj){
                Rj = newR;
                tmp = Rj - Ri;
                if (tmp > maxProfit)
                    maxProfit = tmp;
                continue;
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            newR = Integer.parseInt(scan.nextLine());
            if (i == 0){
                Rj = newR;
                Ri = newR;
                continue;
            }
            if (newR < Ri){
                tmp = newR - Ri;
                if (tmp > tmpProfit)
                    tmpProfit = tmp;
                Ri = newR;
                Rj = newR;
                continue;
            }
            if (newR >= Rj){
                Rj = newR;
                tmp = Rj - Ri;
                if (tmp > maxProfit)
                    maxProfit = tmp;
                continue;
            }
        } {
            newR = Integer.parseInt(scan.nextLine());
            if (i == 0){
                Rj = newR;
                Ri = newR;
                continue;
            }
            if (newR < Ri){
                tmp = newR - Ri;
                if (tmp > tmpProfit)
                    tmpProfit = tmp;
                Ri = newR;
                Rj = newR;
                continue;
            }
            if (newR >= Rj){
                Rj = newR;
                tmp = Rj - Ri;
                if (tmp > maxProfit)
                    maxProfit = tmp;
                continue;
            }
        } newR = Integer.parseInt(scan.nextLine()) newR Integer.parseInt(scan.nextLine()) Integer.parseInt Integer scan.nextLine() scan.nextLine scan if (i == 0){
                Rj = newR;
                Ri = newR;
                continue;
            } i == 0 i 0 {
                Rj = newR;
                Ri = newR;
                continue;
            } Rj = newR Rj newR Ri = newR Ri newR continue; if (newR < Ri){
                tmp = newR - Ri;
                if (tmp > tmpProfit)
                    tmpProfit = tmp;
                Ri = newR;
                Rj = newR;
                continue;
            } newR < Ri newR Ri {
                tmp = newR - Ri;
                if (tmp > tmpProfit)
                    tmpProfit = tmp;
                Ri = newR;
                Rj = newR;
                continue;
            } tmp = newR - Ri tmp newR - Ri newR Ri if (tmp > tmpProfit)
                    tmpProfit = tmp; tmp > tmpProfit tmp tmpProfit tmpProfit = tmp tmpProfit tmp Ri = newR Ri newR Rj = newR Rj newR continue; if (newR >= Rj){
                Rj = newR;
                tmp = Rj - Ri;
                if (tmp > maxProfit)
                    maxProfit = tmp;
                continue;
            } newR >= Rj newR Rj {
                Rj = newR;
                tmp = Rj - Ri;
                if (tmp > maxProfit)
                    maxProfit = tmp;
                continue;
            } Rj = newR Rj newR tmp = Rj - Ri tmp Rj - Ri Rj Ri if (tmp > maxProfit)
                    maxProfit = tmp; tmp > maxProfit tmp maxProfit maxProfit = tmp maxProfit tmp continue; if (tmpProfit > maxProfit)
            maxProfit = tmpProfit;
        else if (tmpProfit == maxProfit)
            maxProfit = 0; tmpProfit > maxProfit tmpProfit maxProfit maxProfit = tmpProfit maxProfit tmpProfit if (tmpProfit == maxProfit)
            maxProfit = 0; tmpProfit == maxProfit tmpProfit maxProfit maxProfit = 0 maxProfit 0 System.out.println((int)(maxProfit)) System.out.println System.out System System.out (int)(maxProfit) String[] args args
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        int n = Integer.parseInt(scan.nextLine());
        double Rj = 0;
        double Ri = 0;
        double newR;
        double maxProfit = -1000000000;
        double tmpProfit = -1000000000;
        double tmp = 0;

        int value;
        for (int i=0; i<n; i++){
            newR = Integer.parseInt(scan.nextLine());
            if (i == 0){
                Rj = newR;
                Ri = newR;
                continue;
            }
            if (newR < Ri){
                tmp = newR - Ri;
                if (tmp > tmpProfit)
                    tmpProfit = tmp;
                Ri = newR;
                Rj = newR;
                continue;
            }
            if (newR >= Rj){
                Rj = newR;
                tmp = Rj - Ri;
                if (tmp > maxProfit)
                    maxProfit = tmp;
                continue;
            }
        }

        if (tmpProfit > maxProfit)
            maxProfit = tmpProfit;
        else if (tmpProfit == maxProfit)
            maxProfit = 0;

        System.out.println((int)(maxProfit));
    }
}