import java.util.Scanner;

public class Main{


	public static void main(String[] args){

		int n;

		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		int[] box=new int[n];
		int max=-1000000001;
		int min=1000000001;

		for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		}

		for(int i=0;i<n-1;i++){

			if(min>box[i]){
			for(int j=i+1;j<n;j++){
				if(box[j]-box[i]>0&&min>box[i])min=box[i];
				if(max<box[j]-box[i])max=box[j]-box[i];
			}
			}//if(min>box[i])
		}
		System.out.println(max);



		scan.close();

	}

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


	public static void main(String[] args){

		int n;

		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		int[] box=new int[n];
		int max=-1000000001;
		int min=1000000001;

		for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		}

		for(int i=0;i<n-1;i++){

			if(min>box[i]){
			for(int j=i+1;j<n;j++){
				if(box[j]-box[i]>0&&min>box[i])min=box[i];
				if(max<box[j]-box[i])max=box[j]-box[i];
			}
			}//if(min>box[i])
		}
		System.out.println(max);



		scan.close();

	}

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

		int n;

		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		int[] box=new int[n];
		int max=-1000000001;
		int min=1000000001;

		for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		}

		for(int i=0;i<n-1;i++){

			if(min>box[i]){
			for(int j=i+1;j<n;j++){
				if(box[j]-box[i]>0&&min>box[i])min=box[i];
				if(max<box[j]-box[i])max=box[j]-box[i];
			}
			}//if(min>box[i])
		}
		System.out.println(max);



		scan.close();

	} main {

		int n;

		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		int[] box=new int[n];
		int max=-1000000001;
		int min=1000000001;

		for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		}

		for(int i=0;i<n-1;i++){

			if(min>box[i]){
			for(int j=i+1;j<n;j++){
				if(box[j]-box[i]>0&&min>box[i])min=box[i];
				if(max<box[j]-box[i])max=box[j]-box[i];
			}
			}//if(min>box[i])
		}
		System.out.println(max);



		scan.close();

	} int n; n Scanner scan=new Scanner(System.in); scan new Scanner(System.in) n=scan.nextInt() n scan.nextInt() scan.nextInt scan int[] box=new int[n]; box new int[n] n int max=-1000000001; max -1000000001 1000000001 int min=1000000001; min 1000000001 for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
		box[i]=scan.nextInt();
		} {
		box[i]=scan.nextInt();
		} box[i]=scan.nextInt() box[i] box i scan.nextInt() scan.nextInt scan for(int i=0;i<n-1;i++){

			if(min>box[i]){
			for(int j=i+1;j<n;j++){
				if(box[j]-box[i]>0&&min>box[i])min=box[i];
				if(max<box[j]-box[i])max=box[j]-box[i];
			}
			}//if(min>box[i])
		} int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {

			if(min>box[i]){
			for(int j=i+1;j<n;j++){
				if(box[j]-box[i]>0&&min>box[i])min=box[i];
				if(max<box[j]-box[i])max=box[j]-box[i];
			}
			}//if(min>box[i])
		} {

			if(min>box[i]){
			for(int j=i+1;j<n;j++){
				if(box[j]-box[i]>0&&min>box[i])min=box[i];
				if(max<box[j]-box[i])max=box[j]-box[i];
			}
			}//if(min>box[i])
		} if(min>box[i]){
			for(int j=i+1;j<n;j++){
				if(box[j]-box[i]>0&&min>box[i])min=box[i];
				if(max<box[j]-box[i])max=box[j]-box[i];
			}
			}//if(min>box[i]) min>box[i] min box[i] box i {
			for(int j=i+1;j<n;j++){
				if(box[j]-box[i]>0&&min>box[i])min=box[i];
				if(max<box[j]-box[i])max=box[j]-box[i];
			}
			} for(int j=i+1;j<n;j++){
				if(box[j]-box[i]>0&&min>box[i])min=box[i];
				if(max<box[j]-box[i])max=box[j]-box[i];
			} int j=i+1; int j=i+1; j i+1 i 1 j<n j n j++ j++ j {
				if(box[j]-box[i]>0&&min>box[i])min=box[i];
				if(max<box[j]-box[i])max=box[j]-box[i];
			} {
				if(box[j]-box[i]>0&&min>box[i])min=box[i];
				if(max<box[j]-box[i])max=box[j]-box[i];
			} if(box[j]-box[i]>0&&min>box[i])min=box[i]; box[j]-box[i]>0&&min>box[i] box[j]-box[i]>0 box[j]-box[i] box[j] box j box[i] box i 0 min>box[i] min box[i] box i min=box[i] min box[i] box i if(max<box[j]-box[i])max=box[j]-box[i]; max<box[j]-box[i] max box[j]-box[i] box[j] box j box[i] box i max=box[j]-box[i] max box[j]-box[i] box[j] box j box[i] box i System.out.println(max) System.out.println System.out System System.out max scan.close() scan.close scan String[] args args public class Main{


	public static void main(String[] args){

		int n;

		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		int[] box=new int[n];
		int max=-1000000001;
		int min=1000000001;

		for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		}

		for(int i=0;i<n-1;i++){

			if(min>box[i]){
			for(int j=i+1;j<n;j++){
				if(box[j]-box[i]>0&&min>box[i])min=box[i];
				if(max<box[j]-box[i])max=box[j]-box[i];
			}
			}//if(min>box[i])
		}
		System.out.println(max);



		scan.close();

	}

} public class Main{


	public static void main(String[] args){

		int n;

		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		int[] box=new int[n];
		int max=-1000000001;
		int min=1000000001;

		for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		}

		for(int i=0;i<n-1;i++){

			if(min>box[i]){
			for(int j=i+1;j<n;j++){
				if(box[j]-box[i]>0&&min>box[i])min=box[i];
				if(max<box[j]-box[i])max=box[j]-box[i];
			}
			}//if(min>box[i])
		}
		System.out.println(max);



		scan.close();

	}

} Main
import java.util.Scanner;

public class Main{


	public static void main(String[] args){

		int n;

		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		int[] box=new int[n];
		int max=-1000000001;
		int min=1000000001;

		for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		}

		for(int i=0;i<n-1;i++){

			if(min>box[i]){
			for(int j=i+1;j<n;j++){
				if(box[j]-box[i]>0&&min>box[i])min=box[i];
				if(max<box[j]-box[i])max=box[j]-box[i];
			}
			}//if(min>box[i])
		}
		System.out.println(max);



		scan.close();

	}

}