import java.util.; import java.io.; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str = null; while((str = in.readLine()) != null){ int n = Integer.parseInt(str); String[] arr = in.readLine().split(" "); int[] res = new int[n]; for(int i = 0;i < n;i++){ res[i] = Integer.parseInt(arr[i]); } if(n ==1){ System.out.println(0); continue; } if(n == 2){ if(res[1] > res[0]){ System.out.println(res[1] - res[0]); continue; }else{ System.out.println(0); continue; } } int[] dest = new int[n]; dest[0] = 0; dest[1] = res[1] - res[0]; int max = dest[1]; for(int i = 2;i < n;i++){ dest[i] = Math.max(res[i] - res[i-1],res[i] - res[i-1]+dest[i-1]); if(dest[i] > max){ max = dest[i]; } } if(max > 0){ System.out.println(max); }else{ System.out.println(0); } } } }