import java.util.Scanner;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(reader.readLine());
String[] s = reader.readLine().split(" ");
int[] arr = new int[n];
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(s[i]);
}
int min=Integer.MAX_VALUE;
int ans=0;
//主要逻辑:
for(int i=0;i<n;i++){
if(arr[i]<min){
min=arr[i];
continue;
}
if(arr[i]>min){
ans=Math.max(ans,arr[i]-min);
}
}
System.out.print(ans);
}
}