import java.util.Scanner;

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

	int n;
	int temp;
	int max = Integer.MIN_VALUE;
	int i;

	Scanner scan = new Scanner(System.in);

	n =  scan.nextInt();
	int m[] = new int[n];
	for(i=0; i<n ; i++)
		m[i] = scan.nextInt();

	temp = m[0];
	for(i=1 ; i<n ; i++){
		if(m[i]-temp > max)
			max = m[i]-temp;
		if(temp > m[i])
			temp = m[i];
	}

	System.out.println(max);

	return;

  }

} import java.util.Scanner; Scanner java.util class Main{
  public static void main(String args[]){

	int n;
	int temp;
	int max = Integer.MIN_VALUE;
	int i;

	Scanner scan = new Scanner(System.in);

	n =  scan.nextInt();
	int m[] = new int[n];
	for(i=0; i<n ; i++)
		m[i] = scan.nextInt();

	temp = m[0];
	for(i=1 ; i<n ; i++){
		if(m[i]-temp > max)
			max = m[i]-temp;
		if(temp > m[i])
			temp = m[i];
	}

	System.out.println(max);

	return;

  }

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

	int n;
	int temp;
	int max = Integer.MIN_VALUE;
	int i;

	Scanner scan = new Scanner(System.in);

	n =  scan.nextInt();
	int m[] = new int[n];
	for(i=0; i<n ; i++)
		m[i] = scan.nextInt();

	temp = m[0];
	for(i=1 ; i<n ; i++){
		if(m[i]-temp > max)
			max = m[i]-temp;
		if(temp > m[i])
			temp = m[i];
	}

	System.out.println(max);

	return;

  } main {

	int n;
	int temp;
	int max = Integer.MIN_VALUE;
	int i;

	Scanner scan = new Scanner(System.in);

	n =  scan.nextInt();
	int m[] = new int[n];
	for(i=0; i<n ; i++)
		m[i] = scan.nextInt();

	temp = m[0];
	for(i=1 ; i<n ; i++){
		if(m[i]-temp > max)
			max = m[i]-temp;
		if(temp > m[i])
			temp = m[i];
	}

	System.out.println(max);

	return;

  } int n; n int temp; temp int max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE int i; i Scanner scan = new Scanner(System.in); scan new Scanner(System.in) n =  scan.nextInt() n scan.nextInt() scan.nextInt scan int m[] = new int[n]; m new int[n] n for(i=0; i<n ; i++)
		m[i] = scan.nextInt(); i=0; i=0 i 0 i<n i n i++ i++ i m[i] = scan.nextInt(); m[i] = scan.nextInt() m[i] m i scan.nextInt() scan.nextInt scan temp = m[0] temp m[0] m 0 for(i=1 ; i<n ; i++){
		if(m[i]-temp > max)
			max = m[i]-temp;
		if(temp > m[i])
			temp = m[i];
	} i=1 ; i=1 i 1 i<n i n i++ i++ i {
		if(m[i]-temp > max)
			max = m[i]-temp;
		if(temp > m[i])
			temp = m[i];
	} {
		if(m[i]-temp > max)
			max = m[i]-temp;
		if(temp > m[i])
			temp = m[i];
	} if(m[i]-temp > max)
			max = m[i]-temp; m[i]-temp > max m[i]-temp m[i] m i temp max max = m[i]-temp max m[i]-temp m[i] m i temp if(temp > m[i])
			temp = m[i]; temp > m[i] temp m[i] m i temp = m[i] temp m[i] m i System.out.println(max) System.out.println System.out System System.out max return; String args[] args
import java.util.Scanner;

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

	int n;
	int temp;
	int max = Integer.MIN_VALUE;
	int i;

	Scanner scan = new Scanner(System.in);

	n =  scan.nextInt();
	int m[] = new int[n];
	for(i=0; i<n ; i++)
		m[i] = scan.nextInt();

	temp = m[0];
	for(i=1 ; i<n ; i++){
		if(m[i]-temp > max)
			max = m[i]-temp;
		if(temp > m[i])
			temp = m[i];
	}

	System.out.println(max);

	return;

  }

}