import java.util.Scanner;

class Main{

	public static void main(String[] args){

		Scanner sc =new Scanner(System.in);

		int n=sc.nextInt();
		int R[];
		R=new int[n];

		for(int i=0;i<n;i++) 
			R[i]=sc.nextInt();

		int max=R[1]-R[0];
		int min=R[0];

		for(int i=0;i<n;i++) {
			if(R[i]<min) min=R[i];
			for(int j=i+1;j<n;j++)
				if (min<R[i]) break;
				else if(R[j]-R[i]>max)
					max=R[j]-R[i];
		}

		System.out.println(max);

	}

} import java.util.Scanner; Scanner java.util class Main{

	public static void main(String[] args){

		Scanner sc =new Scanner(System.in);

		int n=sc.nextInt();
		int R[];
		R=new int[n];

		for(int i=0;i<n;i++) 
			R[i]=sc.nextInt();

		int max=R[1]-R[0];
		int min=R[0];

		for(int i=0;i<n;i++) {
			if(R[i]<min) min=R[i];
			for(int j=i+1;j<n;j++)
				if (min<R[i]) break;
				else if(R[j]-R[i]>max)
					max=R[j]-R[i];
		}

		System.out.println(max);

	}

} Main public static void main(String[] args){

		Scanner sc =new Scanner(System.in);

		int n=sc.nextInt();
		int R[];
		R=new int[n];

		for(int i=0;i<n;i++) 
			R[i]=sc.nextInt();

		int max=R[1]-R[0];
		int min=R[0];

		for(int i=0;i<n;i++) {
			if(R[i]<min) min=R[i];
			for(int j=i+1;j<n;j++)
				if (min<R[i]) break;
				else if(R[j]-R[i]>max)
					max=R[j]-R[i];
		}

		System.out.println(max);

	} main {

		Scanner sc =new Scanner(System.in);

		int n=sc.nextInt();
		int R[];
		R=new int[n];

		for(int i=0;i<n;i++) 
			R[i]=sc.nextInt();

		int max=R[1]-R[0];
		int min=R[0];

		for(int i=0;i<n;i++) {
			if(R[i]<min) min=R[i];
			for(int j=i+1;j<n;j++)
				if (min<R[i]) break;
				else if(R[j]-R[i]>max)
					max=R[j]-R[i];
		}

		System.out.println(max);

	} Scanner sc =new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int R[]; R R=new int[n] R new int[n] n for(int i=0;i<n;i++) 
			R[i]=sc.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i R[i]=sc.nextInt(); R[i]=sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc int max=R[1]-R[0]; max R[1]-R[0] R[1] R 1 R[0] R 0 int min=R[0]; min R[0] R 0 for(int i=0;i<n;i++) {
			if(R[i]<min) min=R[i];
			for(int j=i+1;j<n;j++)
				if (min<R[i]) break;
				else if(R[j]-R[i]>max)
					max=R[j]-R[i];
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			if(R[i]<min) min=R[i];
			for(int j=i+1;j<n;j++)
				if (min<R[i]) break;
				else if(R[j]-R[i]>max)
					max=R[j]-R[i];
		} {
			if(R[i]<min) min=R[i];
			for(int j=i+1;j<n;j++)
				if (min<R[i]) break;
				else if(R[j]-R[i]>max)
					max=R[j]-R[i];
		} if(R[i]<min) min=R[i]; R[i]<min R[i] R i min min=R[i] min R[i] R i for(int j=i+1;j<n;j++)
				if (min<R[i]) break;
				else if(R[j]-R[i]>max)
					max=R[j]-R[i]; int j=i+1; int j=i+1; j i+1 i 1 j<n j n j++ j++ j if (min<R[i]) break;
				else if(R[j]-R[i]>max)
					max=R[j]-R[i]; if (min<R[i]) break;
				else if(R[j]-R[i]>max)
					max=R[j]-R[i]; min<R[i] min R[i] R i break; if(R[j]-R[i]>max)
					max=R[j]-R[i]; R[j]-R[i]>max R[j]-R[i] R[j] R j R[i] R i max max=R[j]-R[i] max R[j]-R[i] R[j] R j R[i] R i System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.util.Scanner;

class Main{

	public static void main(String[] args){

		Scanner sc =new Scanner(System.in);

		int n=sc.nextInt();
		int R[];
		R=new int[n];

		for(int i=0;i<n;i++) 
			R[i]=sc.nextInt();

		int max=R[1]-R[0];
		int min=R[0];

		for(int i=0;i<n;i++) {
			if(R[i]<min) min=R[i];
			for(int j=i+1;j<n;j++)
				if (min<R[i]) break;
				else if(R[j]-R[i]>max)
					max=R[j]-R[i];
		}

		System.out.println(max);

	}

}
