import java.util.Scanner;

public class Main {

    public int size;
    public int[] mx;

    public void scan() {
        Scanner sc = new Scanner(System.in);
        this.size = sc.nextInt();
        this.mx = new int[this.size];
        for (int i = 0; i < this.size; i++) {
            this.mx[i] = sc.nextInt();
        }
    }

    public void task() {
        int min = this.mx[0];
        int max = this.mx[1] - this.mx[0];
        for(int i = 1; i < this.size; i++){
            if(max < this.mx[i] - min){ max = this.mx[i] - min; }
            if(min > this.mx[i]){ min = this.mx[i]; }
        }
        System.out.println(max);
    }

    public static void main(String[] args) {
        Main prime = new Main();
        prime.scan();
        prime.task();
    }
}

/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz