import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * Created by martin-d28jp-love on 15/04/01.
 */
public class Main {

    public static void main(String[] args) {
        int[] input = input();
//        int[] input = mockuop();

        int inputLength = input.length;
        int minValue = Integer.MAX_VALUE;
        int maxValue = -Integer.MAX_VALUE;
        int minIndex = 0;
        int maxIndex = 0;
        for (int i=0; i < inputLength; i++) {
            int Ri = input[i];
            if (Ri < minValue) {
                minValue = Ri;
                minIndex = i;
            }
            if (Ri > maxValue) {
                maxValue = Ri;
                maxIndex = i;
            }
        }
        if (minIndex < maxIndex) {
            System.out.println(maxValue - minValue);
            return;
        }

        int maxSubtruction = -Integer.MAX_VALUE;
        int maxSubtructionIndex = 0;
        int beforeSubtructionRi = Integer.MAX_VALUE;
        for (int i = 0; i < inputLength - 1; i++) {
            int Ri = input[i];
            if (beforeSubtructionRi < Ri) {
                continue;
            }
            int start = maxSubtructionIndex > i + 1 ? maxSubtructionIndex : i + 1;
            for (int j = start; j < inputLength; j++) {
                int Rj = input[j];
                if (Rj - Ri > maxSubtruction) {
                    maxSubtruction = Rj - Ri;
                    maxSubtructionIndex = j;
                    beforeSubtructionRi = Ri;
                }
            }
        }
        System.out.println(maxSubtruction);
    }

    public static int[] mockuop() {
        int input[] = {20,100,99,95,86,85,76,75,71,70,61,52,48,47,43,42,38,37,33,32,28};
        return input;
    }

    public static int[] input() {
        Scanner in = new Scanner(System.in);
        int size = Integer.valueOf(in.nextLine());

        int[] input = new int[size];
        int i = 0;
        while(in.hasNext()) {
            input[i++] = Integer.valueOf(in.nextLine());
        }
        in.close();
        return input;
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        int[] input = input();
//        int[] input = mockuop();

        int inputLength = input.length;
        int minValue = Integer.MAX_VALUE;
        int maxValue = -Integer.MAX_VALUE;
        int minIndex = 0;
        int maxIndex = 0;
        for (int i=0; i < inputLength; i++) {
            int Ri = input[i];
            if (Ri < minValue) {
                minValue = Ri;
                minIndex = i;
            }
            if (Ri > maxValue) {
                maxValue = Ri;
                maxIndex = i;
            }
        }
        if (minIndex < maxIndex) {
            System.out.println(maxValue - minValue);
            return;
        }

        int maxSubtruction = -Integer.MAX_VALUE;
        int maxSubtructionIndex = 0;
        int beforeSubtructionRi = Integer.MAX_VALUE;
        for (int i = 0; i < inputLength - 1; i++) {
            int Ri = input[i];
            if (beforeSubtructionRi < Ri) {
                continue;
            }
            int start = maxSubtructionIndex > i + 1 ? maxSubtructionIndex : i + 1;
            for (int j = start; j < inputLength; j++) {
                int Rj = input[j];
                if (Rj - Ri > maxSubtruction) {
                    maxSubtruction = Rj - Ri;
                    maxSubtructionIndex = j;
                    beforeSubtructionRi = Ri;
                }
            }
        }
        System.out.println(maxSubtruction);
    }

    public static int[] mockuop() {
        int input[] = {20,100,99,95,86,85,76,75,71,70,61,52,48,47,43,42,38,37,33,32,28};
        return input;
    }

    public static int[] input() {
        Scanner in = new Scanner(System.in);
        int size = Integer.valueOf(in.nextLine());

        int[] input = new int[size];
        int i = 0;
        while(in.hasNext()) {
            input[i++] = Integer.valueOf(in.nextLine());
        }
        in.close();
        return input;
    }
} Main public static void main(String[] args) {
        int[] input = input();
//        int[] input = mockuop();

        int inputLength = input.length;
        int minValue = Integer.MAX_VALUE;
        int maxValue = -Integer.MAX_VALUE;
        int minIndex = 0;
        int maxIndex = 0;
        for (int i=0; i < inputLength; i++) {
            int Ri = input[i];
            if (Ri < minValue) {
                minValue = Ri;
                minIndex = i;
            }
            if (Ri > maxValue) {
                maxValue = Ri;
                maxIndex = i;
            }
        }
        if (minIndex < maxIndex) {
            System.out.println(maxValue - minValue);
            return;
        }

        int maxSubtruction = -Integer.MAX_VALUE;
        int maxSubtructionIndex = 0;
        int beforeSubtructionRi = Integer.MAX_VALUE;
        for (int i = 0; i < inputLength - 1; i++) {
            int Ri = input[i];
            if (beforeSubtructionRi < Ri) {
                continue;
            }
            int start = maxSubtructionIndex > i + 1 ? maxSubtructionIndex : i + 1;
            for (int j = start; j < inputLength; j++) {
                int Rj = input[j];
                if (Rj - Ri > maxSubtruction) {
                    maxSubtruction = Rj - Ri;
                    maxSubtructionIndex = j;
                    beforeSubtructionRi = Ri;
                }
            }
        }
        System.out.println(maxSubtruction);
    } main {
        int[] input = input();
//        int[] input = mockuop();

        int inputLength = input.length;
        int minValue = Integer.MAX_VALUE;
        int maxValue = -Integer.MAX_VALUE;
        int minIndex = 0;
        int maxIndex = 0;
        for (int i=0; i < inputLength; i++) {
            int Ri = input[i];
            if (Ri < minValue) {
                minValue = Ri;
                minIndex = i;
            }
            if (Ri > maxValue) {
                maxValue = Ri;
                maxIndex = i;
            }
        }
        if (minIndex < maxIndex) {
            System.out.println(maxValue - minValue);
            return;
        }

        int maxSubtruction = -Integer.MAX_VALUE;
        int maxSubtructionIndex = 0;
        int beforeSubtructionRi = Integer.MAX_VALUE;
        for (int i = 0; i < inputLength - 1; i++) {
            int Ri = input[i];
            if (beforeSubtructionRi < Ri) {
                continue;
            }
            int start = maxSubtructionIndex > i + 1 ? maxSubtructionIndex : i + 1;
            for (int j = start; j < inputLength; j++) {
                int Rj = input[j];
                if (Rj - Ri > maxSubtruction) {
                    maxSubtruction = Rj - Ri;
                    maxSubtructionIndex = j;
                    beforeSubtructionRi = Ri;
                }
            }
        }
        System.out.println(maxSubtruction);
    } int[] input = input(); input input() input int inputLength = input.length; inputLength input.length input input.length int minValue = Integer.MAX_VALUE; minValue Integer.MAX_VALUE Integer Integer.MAX_VALUE int maxValue = -Integer.MAX_VALUE; maxValue -Integer.MAX_VALUE Integer.MAX_VALUE Integer Integer.MAX_VALUE int minIndex = 0; minIndex 0 int maxIndex = 0; maxIndex 0 for (int i=0; i < inputLength; i++) {
            int Ri = input[i];
            if (Ri < minValue) {
                minValue = Ri;
                minIndex = i;
            }
            if (Ri > maxValue) {
                maxValue = Ri;
                maxIndex = i;
            }
        } int i=0; int i=0; i 0 i < inputLength i inputLength i++ i++ i {
            int Ri = input[i];
            if (Ri < minValue) {
                minValue = Ri;
                minIndex = i;
            }
            if (Ri > maxValue) {
                maxValue = Ri;
                maxIndex = i;
            }
        } {
            int Ri = input[i];
            if (Ri < minValue) {
                minValue = Ri;
                minIndex = i;
            }
            if (Ri > maxValue) {
                maxValue = Ri;
                maxIndex = i;
            }
        } int Ri = input[i]; Ri input[i] input i if (Ri < minValue) {
                minValue = Ri;
                minIndex = i;
            } Ri < minValue Ri minValue {
                minValue = Ri;
                minIndex = i;
            } minValue = Ri minValue Ri minIndex = i minIndex i if (Ri > maxValue) {
                maxValue = Ri;
                maxIndex = i;
            } Ri > maxValue Ri maxValue {
                maxValue = Ri;
                maxIndex = i;
            } maxValue = Ri maxValue Ri maxIndex = i maxIndex i if (minIndex < maxIndex) {
            System.out.println(maxValue - minValue);
            return;
        } minIndex < maxIndex minIndex maxIndex {
            System.out.println(maxValue - minValue);
            return;
        } System.out.println(maxValue - minValue) System.out.println System.out System System.out maxValue - minValue maxValue minValue return; int maxSubtruction = -Integer.MAX_VALUE; maxSubtruction -Integer.MAX_VALUE Integer.MAX_VALUE Integer Integer.MAX_VALUE int maxSubtructionIndex = 0; maxSubtructionIndex 0 int beforeSubtructionRi = Integer.MAX_VALUE; beforeSubtructionRi Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i < inputLength - 1; i++) {
            int Ri = input[i];
            if (beforeSubtructionRi < Ri) {
                continue;
            }
            int start = maxSubtructionIndex > i + 1 ? maxSubtructionIndex : i + 1;
            for (int j = start; j < inputLength; j++) {
                int Rj = input[j];
                if (Rj - Ri > maxSubtruction) {
                    maxSubtruction = Rj - Ri;
                    maxSubtructionIndex = j;
                    beforeSubtructionRi = Ri;
                }
            }
        } int i = 0; int i = 0; i 0 i < inputLength - 1 i inputLength - 1 inputLength 1 i++ i++ i {
            int Ri = input[i];
            if (beforeSubtructionRi < Ri) {
                continue;
            }
            int start = maxSubtructionIndex > i + 1 ? maxSubtructionIndex : i + 1;
            for (int j = start; j < inputLength; j++) {
                int Rj = input[j];
                if (Rj - Ri > maxSubtruction) {
                    maxSubtruction = Rj - Ri;
                    maxSubtructionIndex = j;
                    beforeSubtructionRi = Ri;
                }
            }
        } {
            int Ri = input[i];
            if (beforeSubtructionRi < Ri) {
                continue;
            }
            int start = maxSubtructionIndex > i + 1 ? maxSubtructionIndex : i + 1;
            for (int j = start; j < inputLength; j++) {
                int Rj = input[j];
                if (Rj - Ri > maxSubtruction) {
                    maxSubtruction = Rj - Ri;
                    maxSubtructionIndex = j;
                    beforeSubtructionRi = Ri;
                }
            }
        } int Ri = input[i]; Ri input[i] input i if (beforeSubtructionRi < Ri) {
                continue;
            } beforeSubtructionRi < Ri beforeSubtructionRi Ri {
                continue;
            } continue; int start = maxSubtructionIndex > i + 1 ? maxSubtructionIndex : i + 1; start maxSubtructionIndex > i + 1 ? maxSubtructionIndex : i + 1 maxSubtructionIndex > i + 1 maxSubtructionIndex i + 1 i 1 maxSubtructionIndex i + 1 i 1 for (int j = start; j < inputLength; j++) {
                int Rj = input[j];
                if (Rj - Ri > maxSubtruction) {
                    maxSubtruction = Rj - Ri;
                    maxSubtructionIndex = j;
                    beforeSubtructionRi = Ri;
                }
            } int j = start; int j = start; j start j < inputLength j inputLength j++ j++ j {
                int Rj = input[j];
                if (Rj - Ri > maxSubtruction) {
                    maxSubtruction = Rj - Ri;
                    maxSubtructionIndex = j;
                    beforeSubtructionRi = Ri;
                }
            } {
                int Rj = input[j];
                if (Rj - Ri > maxSubtruction) {
                    maxSubtruction = Rj - Ri;
                    maxSubtructionIndex = j;
                    beforeSubtructionRi = Ri;
                }
            } int Rj = input[j]; Rj input[j] input j if (Rj - Ri > maxSubtruction) {
                    maxSubtruction = Rj - Ri;
                    maxSubtructionIndex = j;
                    beforeSubtructionRi = Ri;
                } Rj - Ri > maxSubtruction Rj - Ri Rj Ri maxSubtruction {
                    maxSubtruction = Rj - Ri;
                    maxSubtructionIndex = j;
                    beforeSubtructionRi = Ri;
                } maxSubtruction = Rj - Ri maxSubtruction Rj - Ri Rj Ri maxSubtructionIndex = j maxSubtructionIndex j beforeSubtructionRi = Ri beforeSubtructionRi Ri System.out.println(maxSubtruction) System.out.println System.out System System.out maxSubtruction String[] args args public static int[] mockuop() {
        int input[] = {20,100,99,95,86,85,76,75,71,70,61,52,48,47,43,42,38,37,33,32,28};
        return input;
    } mockuop {
        int input[] = {20,100,99,95,86,85,76,75,71,70,61,52,48,47,43,42,38,37,33,32,28};
        return input;
    } int input[] = {20,100,99,95,86,85,76,75,71,70,61,52,48,47,43,42,38,37,33,32,28}; input {20,100,99,95,86,85,76,75,71,70,61,52,48,47,43,42,38,37,33,32,28} 20 100 99 95 86 85 76 75 71 70 61 52 48 47 43 42 38 37 33 32 28 return input; input public static int[] input() {
        Scanner in = new Scanner(System.in);
        int size = Integer.valueOf(in.nextLine());

        int[] input = new int[size];
        int i = 0;
        while(in.hasNext()) {
            input[i++] = Integer.valueOf(in.nextLine());
        }
        in.close();
        return input;
    } input {
        Scanner in = new Scanner(System.in);
        int size = Integer.valueOf(in.nextLine());

        int[] input = new int[size];
        int i = 0;
        while(in.hasNext()) {
            input[i++] = Integer.valueOf(in.nextLine());
        }
        in.close();
        return input;
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int size = Integer.valueOf(in.nextLine()); size Integer.valueOf(in.nextLine()) Integer.valueOf Integer in.nextLine() in.nextLine in int[] input = new int[size]; input new int[size] size int i = 0; i 0 while(in.hasNext()) {
            input[i++] = Integer.valueOf(in.nextLine());
        } in.hasNext() in.hasNext in {
            input[i++] = Integer.valueOf(in.nextLine());
        } input[i++] = Integer.valueOf(in.nextLine()) input[i++] input i++ i Integer.valueOf(in.nextLine()) Integer.valueOf Integer in.nextLine() in.nextLine in in.close() in.close in return input; input public class Main {

    public static void main(String[] args) {
        int[] input = input();
//        int[] input = mockuop();

        int inputLength = input.length;
        int minValue = Integer.MAX_VALUE;
        int maxValue = -Integer.MAX_VALUE;
        int minIndex = 0;
        int maxIndex = 0;
        for (int i=0; i < inputLength; i++) {
            int Ri = input[i];
            if (Ri < minValue) {
                minValue = Ri;
                minIndex = i;
            }
            if (Ri > maxValue) {
                maxValue = Ri;
                maxIndex = i;
            }
        }
        if (minIndex < maxIndex) {
            System.out.println(maxValue - minValue);
            return;
        }

        int maxSubtruction = -Integer.MAX_VALUE;
        int maxSubtructionIndex = 0;
        int beforeSubtructionRi = Integer.MAX_VALUE;
        for (int i = 0; i < inputLength - 1; i++) {
            int Ri = input[i];
            if (beforeSubtructionRi < Ri) {
                continue;
            }
            int start = maxSubtructionIndex > i + 1 ? maxSubtructionIndex : i + 1;
            for (int j = start; j < inputLength; j++) {
                int Rj = input[j];
                if (Rj - Ri > maxSubtruction) {
                    maxSubtruction = Rj - Ri;
                    maxSubtructionIndex = j;
                    beforeSubtructionRi = Ri;
                }
            }
        }
        System.out.println(maxSubtruction);
    }

    public static int[] mockuop() {
        int input[] = {20,100,99,95,86,85,76,75,71,70,61,52,48,47,43,42,38,37,33,32,28};
        return input;
    }

    public static int[] input() {
        Scanner in = new Scanner(System.in);
        int size = Integer.valueOf(in.nextLine());

        int[] input = new int[size];
        int i = 0;
        while(in.hasNext()) {
            input[i++] = Integer.valueOf(in.nextLine());
        }
        in.close();
        return input;
    }
} public class Main {

    public static void main(String[] args) {
        int[] input = input();
//        int[] input = mockuop();

        int inputLength = input.length;
        int minValue = Integer.MAX_VALUE;
        int maxValue = -Integer.MAX_VALUE;
        int minIndex = 0;
        int maxIndex = 0;
        for (int i=0; i < inputLength; i++) {
            int Ri = input[i];
            if (Ri < minValue) {
                minValue = Ri;
                minIndex = i;
            }
            if (Ri > maxValue) {
                maxValue = Ri;
                maxIndex = i;
            }
        }
        if (minIndex < maxIndex) {
            System.out.println(maxValue - minValue);
            return;
        }

        int maxSubtruction = -Integer.MAX_VALUE;
        int maxSubtructionIndex = 0;
        int beforeSubtructionRi = Integer.MAX_VALUE;
        for (int i = 0; i < inputLength - 1; i++) {
            int Ri = input[i];
            if (beforeSubtructionRi < Ri) {
                continue;
            }
            int start = maxSubtructionIndex > i + 1 ? maxSubtructionIndex : i + 1;
            for (int j = start; j < inputLength; j++) {
                int Rj = input[j];
                if (Rj - Ri > maxSubtruction) {
                    maxSubtruction = Rj - Ri;
                    maxSubtructionIndex = j;
                    beforeSubtructionRi = Ri;
                }
            }
        }
        System.out.println(maxSubtruction);
    }

    public static int[] mockuop() {
        int input[] = {20,100,99,95,86,85,76,75,71,70,61,52,48,47,43,42,38,37,33,32,28};
        return input;
    }

    public static int[] input() {
        Scanner in = new Scanner(System.in);
        int size = Integer.valueOf(in.nextLine());

        int[] input = new int[size];
        int i = 0;
        while(in.hasNext()) {
            input[i++] = Integer.valueOf(in.nextLine());
        }
        in.close();
        return input;
    }
} Main
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * Created by martin-d28jp-love on 15/04/01.
 */
public class Main {

    public static void main(String[] args) {
        int[] input = input();
//        int[] input = mockuop();

        int inputLength = input.length;
        int minValue = Integer.MAX_VALUE;
        int maxValue = -Integer.MAX_VALUE;
        int minIndex = 0;
        int maxIndex = 0;
        for (int i=0; i < inputLength; i++) {
            int Ri = input[i];
            if (Ri < minValue) {
                minValue = Ri;
                minIndex = i;
            }
            if (Ri > maxValue) {
                maxValue = Ri;
                maxIndex = i;
            }
        }
        if (minIndex < maxIndex) {
            System.out.println(maxValue - minValue);
            return;
        }

        int maxSubtruction = -Integer.MAX_VALUE;
        int maxSubtructionIndex = 0;
        int beforeSubtructionRi = Integer.MAX_VALUE;
        for (int i = 0; i < inputLength - 1; i++) {
            int Ri = input[i];
            if (beforeSubtructionRi < Ri) {
                continue;
            }
            int start = maxSubtructionIndex > i + 1 ? maxSubtructionIndex : i + 1;
            for (int j = start; j < inputLength; j++) {
                int Rj = input[j];
                if (Rj - Ri > maxSubtruction) {
                    maxSubtruction = Rj - Ri;
                    maxSubtructionIndex = j;
                    beforeSubtructionRi = Ri;
                }
            }
        }
        System.out.println(maxSubtruction);
    }

    public static int[] mockuop() {
        int input[] = {20,100,99,95,86,85,76,75,71,70,61,52,48,47,43,42,38,37,33,32,28};
        return input;
    }

    public static int[] input() {
        Scanner in = new Scanner(System.in);
        int size = Integer.valueOf(in.nextLine());

        int[] input = new int[size];
        int i = 0;
        while(in.hasNext()) {
            input[i++] = Integer.valueOf(in.nextLine());
        }
        in.close();
        return input;
    }
}