import java.util.*;

public class Main{
	public static void  main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int buy,ans,rem;
		ans = Integer.MIN_VALUE;
		
		buy = sc.nextInt();
		for(int i = 1 ; i < n ; i++ )
		{
			rem = sc.nextInt();
			ans = Math.max(ans , rem - buy);
			buy = Math.min(rem , buy );
			
		}
		
		System.out.println(ans);
		
	}
} import java.util.*; util.* java public class Main{
	public static void  main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int buy,ans,rem;
		ans = Integer.MIN_VALUE;
		
		buy = sc.nextInt();
		for(int i = 1 ; i < n ; i++ )
		{
			rem = sc.nextInt();
			ans = Math.max(ans , rem - buy);
			buy = Math.min(rem , buy );
			
		}
		
		System.out.println(ans);
		
	}
} Main public static void  main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int buy,ans,rem;
		ans = Integer.MIN_VALUE;
		
		buy = sc.nextInt();
		for(int i = 1 ; i < n ; i++ )
		{
			rem = sc.nextInt();
			ans = Math.max(ans , rem - buy);
			buy = Math.min(rem , buy );
			
		}
		
		System.out.println(ans);
		
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int buy,ans,rem;
		ans = Integer.MIN_VALUE;
		
		buy = sc.nextInt();
		for(int i = 1 ; i < n ; i++ )
		{
			rem = sc.nextInt();
			ans = Math.max(ans , rem - buy);
			buy = Math.min(rem , buy );
			
		}
		
		System.out.println(ans);
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int buy buy ans ans rem; rem ans = Integer.MIN_VALUE ans Integer.MIN_VALUE Integer Integer.MIN_VALUE buy = sc.nextInt() buy sc.nextInt() sc.nextInt sc for(int i = 1 ; i < n ; i++ )
		{
			rem = sc.nextInt();
			ans = Math.max(ans , rem - buy);
			buy = Math.min(rem , buy );
			
		} int i = 1 ; int i = 1 ; i 1 i < n i n i++ i++ i {
			rem = sc.nextInt();
			ans = Math.max(ans , rem - buy);
			buy = Math.min(rem , buy );
			
		} {
			rem = sc.nextInt();
			ans = Math.max(ans , rem - buy);
			buy = Math.min(rem , buy );
			
		} rem = sc.nextInt() rem sc.nextInt() sc.nextInt sc ans = Math.max(ans , rem - buy) ans Math.max(ans , rem - buy) Math.max Math ans rem - buy rem buy buy = Math.min(rem , buy ) buy Math.min(rem , buy ) Math.min Math rem buy System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main{
	public static void  main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int buy,ans,rem;
		ans = Integer.MIN_VALUE;
		
		buy = sc.nextInt();
		for(int i = 1 ; i < n ; i++ )
		{
			rem = sc.nextInt();
			ans = Math.max(ans , rem - buy);
			buy = Math.min(rem , buy );
			
		}
		
		System.out.println(ans);
		
	}
} public class Main{
	public static void  main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int buy,ans,rem;
		ans = Integer.MIN_VALUE;
		
		buy = sc.nextInt();
		for(int i = 1 ; i < n ; i++ )
		{
			rem = sc.nextInt();
			ans = Math.max(ans , rem - buy);
			buy = Math.min(rem , buy );
			
		}
		
		System.out.println(ans);
		
	}
} Main
import java.util.*;

public class Main{
	public static void  main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int buy,ans,rem;
		ans = Integer.MIN_VALUE;
		
		buy = sc.nextInt();
		for(int i = 1 ; i < n ; i++ )
		{
			rem = sc.nextInt();
			ans = Math.max(ans , rem - buy);
			buy = Math.min(rem , buy );
			
		}
		
		System.out.println(ans);
		
	}
}