import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import javax.lang.model.util.ElementScanner6;

class Main {
    public static boolean isPrime(int a) {
        for (int i = 2; i <= Math.sqrt(a); i++) {
            if (a % i == 0)
                return false;
        }
        return true;
    }

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            int n = Integer.parseInt(br.readLine());
            int nums[] = new int[n];
            int max, min;
            for (int i = 0; i < n; i++)
                nums[i] = Integer.parseInt(br.readLine());

            /*
             * for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (nums[i] -
             * nums[j] > max) max = nums[i] - nums[j]; } }
             */
            min = nums[0];
            max = -1000000000;
            for (int i = 1; i < n; i++) {
                if (nums[i] - min > max)
                    max = nums[i] - min;
                if (nums[i] < min)
                    min = nums[i];
            }
            System.out.println(max);

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import javax.lang.model.util.ElementScanner6; ElementScanner6 javax.lang.model.util class Main {
    public static boolean isPrime(int a) {
        for (int i = 2; i <= Math.sqrt(a); i++) {
            if (a % i == 0)
                return false;
        }
        return true;
    }

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            int n = Integer.parseInt(br.readLine());
            int nums[] = new int[n];
            int max, min;
            for (int i = 0; i < n; i++)
                nums[i] = Integer.parseInt(br.readLine());

            /*
             * for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (nums[i] -
             * nums[j] > max) max = nums[i] - nums[j]; } }
             */
            min = nums[0];
            max = -1000000000;
            for (int i = 1; i < n; i++) {
                if (nums[i] - min > max)
                    max = nums[i] - min;
                if (nums[i] < min)
                    min = nums[i];
            }
            System.out.println(max);

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
} Main public static boolean isPrime(int a) {
        for (int i = 2; i <= Math.sqrt(a); i++) {
            if (a % i == 0)
                return false;
        }
        return true;
    } isPrime {
        for (int i = 2; i <= Math.sqrt(a); i++) {
            if (a % i == 0)
                return false;
        }
        return true;
    } for (int i = 2; i <= Math.sqrt(a); i++) {
            if (a % i == 0)
                return false;
        } int i = 2; int i = 2; i 2 i <= Math.sqrt(a) i Math.sqrt(a) Math.sqrt Math a i++ i++ i {
            if (a % i == 0)
                return false;
        } {
            if (a % i == 0)
                return false;
        } if (a % i == 0)
                return false; a % i == 0 a % i a i 0 return false; false return true; true int a a public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            int n = Integer.parseInt(br.readLine());
            int nums[] = new int[n];
            int max, min;
            for (int i = 0; i < n; i++)
                nums[i] = Integer.parseInt(br.readLine());

            /*
             * for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (nums[i] -
             * nums[j] > max) max = nums[i] - nums[j]; } }
             */
            min = nums[0];
            max = -1000000000;
            for (int i = 1; i < n; i++) {
                if (nums[i] - min > max)
                    max = nums[i] - min;
                if (nums[i] < min)
                    min = nums[i];
            }
            System.out.println(max);

        } catch (IOException e) {
            e.printStackTrace();
        }

    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            int n = Integer.parseInt(br.readLine());
            int nums[] = new int[n];
            int max, min;
            for (int i = 0; i < n; i++)
                nums[i] = Integer.parseInt(br.readLine());

            /*
             * for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (nums[i] -
             * nums[j] > max) max = nums[i] - nums[j]; } }
             */
            min = nums[0];
            max = -1000000000;
            for (int i = 1; i < n; i++) {
                if (nums[i] - min > max)
                    max = nums[i] - min;
                if (nums[i] < min)
                    min = nums[i];
            }
            System.out.println(max);

        } catch (IOException e) {
            e.printStackTrace();
        }

    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) try {
            int n = Integer.parseInt(br.readLine());
            int nums[] = new int[n];
            int max, min;
            for (int i = 0; i < n; i++)
                nums[i] = Integer.parseInt(br.readLine());

            /*
             * for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (nums[i] -
             * nums[j] > max) max = nums[i] - nums[j]; } }
             */
            min = nums[0];
            max = -1000000000;
            for (int i = 1; i < n; i++) {
                if (nums[i] - min > max)
                    max = nums[i] - min;
                if (nums[i] < min)
                    min = nums[i];
            }
            System.out.println(max);

        } catch (IOException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } IOException e {
            e.printStackTrace();
        } e.printStackTrace() e.printStackTrace e {
            int n = Integer.parseInt(br.readLine());
            int nums[] = new int[n];
            int max, min;
            for (int i = 0; i < n; i++)
                nums[i] = Integer.parseInt(br.readLine());

            /*
             * for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (nums[i] -
             * nums[j] > max) max = nums[i] - nums[j]; } }
             */
            min = nums[0];
            max = -1000000000;
            for (int i = 1; i < n; i++) {
                if (nums[i] - min > max)
                    max = nums[i] - min;
                if (nums[i] < min)
                    min = nums[i];
            }
            System.out.println(max);

        } int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int nums[] = new int[n]; nums new int[n] n int max max min; min for (int i = 0; i < n; i++)
                nums[i] = Integer.parseInt(br.readLine()); int i = 0; int i = 0; i 0 i < n i n i++ i++ i nums[i] = Integer.parseInt(br.readLine()); nums[i] = Integer.parseInt(br.readLine()) nums[i] nums i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br min = nums[0] min nums[0] nums 0 max = -1000000000 max -1000000000 1000000000 for (int i = 1; i < n; i++) {
                if (nums[i] - min > max)
                    max = nums[i] - min;
                if (nums[i] < min)
                    min = nums[i];
            } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
                if (nums[i] - min > max)
                    max = nums[i] - min;
                if (nums[i] < min)
                    min = nums[i];
            } {
                if (nums[i] - min > max)
                    max = nums[i] - min;
                if (nums[i] < min)
                    min = nums[i];
            } if (nums[i] - min > max)
                    max = nums[i] - min; nums[i] - min > max nums[i] - min nums[i] nums i min max max = nums[i] - min max nums[i] - min nums[i] nums i min if (nums[i] < min)
                    min = nums[i]; nums[i] < min nums[i] nums i min min = nums[i] min nums[i] nums i System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import javax.lang.model.util.ElementScanner6;

class Main {
    public static boolean isPrime(int a) {
        for (int i = 2; i <= Math.sqrt(a); i++) {
            if (a % i == 0)
                return false;
        }
        return true;
    }

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            int n = Integer.parseInt(br.readLine());
            int nums[] = new int[n];
            int max, min;
            for (int i = 0; i < n; i++)
                nums[i] = Integer.parseInt(br.readLine());

            /*
             * for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (nums[i] -
             * nums[j] > max) max = nums[i] - nums[j]; } }
             */
            min = nums[0];
            max = -1000000000;
            for (int i = 1; i < n; i++) {
                if (nums[i] - min > max)
                    max = nums[i] - min;
                if (nums[i] < min)
                    min = nums[i];
            }
            System.out.println(max);

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
