import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
        int i,j,t,k,minv,maxv;
        Scanner scan=new Scanner(System.in);
        t=scan.nextInt();
        int r[]=new int[t+1];
        for(i=0;i<t;i++)
        {
        	r[i]=scan.nextInt();
        }
        minv=r[0];
        maxv=r[1]-r[0];
        for(j=1;j<t;j++)
        {
        	maxv=Math.max(maxv,r[j]-minv);
        	minv=Math.min(minv,r[j]);
        }
        System.out.println(maxv);
	}

} import java.util.*; util.* java import java.io.*; io.* java import static java.util.Arrays.*; import static java.util.Arrays.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.util.Collections.*; import static java.util.Collections.*; import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
        int i,j,t,k,minv,maxv;
        Scanner scan=new Scanner(System.in);
        t=scan.nextInt();
        int r[]=new int[t+1];
        for(i=0;i<t;i++)
        {
        	r[i]=scan.nextInt();
        }
        minv=r[0];
        maxv=r[1]-r[0];
        for(j=1;j<t;j++)
        {
        	maxv=Math.max(maxv,r[j]-minv);
        	minv=Math.min(minv,r[j]);
        }
        System.out.println(maxv);
	}

} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
        int i,j,t,k,minv,maxv;
        Scanner scan=new Scanner(System.in);
        t=scan.nextInt();
        int r[]=new int[t+1];
        for(i=0;i<t;i++)
        {
        	r[i]=scan.nextInt();
        }
        minv=r[0];
        maxv=r[1]-r[0];
        for(j=1;j<t;j++)
        {
        	maxv=Math.max(maxv,r[j]-minv);
        	minv=Math.min(minv,r[j]);
        }
        System.out.println(maxv);
	} main {
		// TODO ?????????????????????????????????????????????
        int i,j,t,k,minv,maxv;
        Scanner scan=new Scanner(System.in);
        t=scan.nextInt();
        int r[]=new int[t+1];
        for(i=0;i<t;i++)
        {
        	r[i]=scan.nextInt();
        }
        minv=r[0];
        maxv=r[1]-r[0];
        for(j=1;j<t;j++)
        {
        	maxv=Math.max(maxv,r[j]-minv);
        	minv=Math.min(minv,r[j]);
        }
        System.out.println(maxv);
	} int i i j j t t k k minv minv maxv; maxv Scanner scan=new Scanner(System.in); scan new Scanner(System.in) t=scan.nextInt() t scan.nextInt() scan.nextInt scan int r[]=new int[t+1]; r new int[t+1] t+1 t 1 for(i=0;i<t;i++)
        {
        	r[i]=scan.nextInt();
        } i=0; i=0 i 0 i<t i t i++ i++ i {
        	r[i]=scan.nextInt();
        } {
        	r[i]=scan.nextInt();
        } r[i]=scan.nextInt() r[i] r i scan.nextInt() scan.nextInt scan minv=r[0] minv r[0] r 0 maxv=r[1]-r[0] maxv r[1]-r[0] r[1] r 1 r[0] r 0 for(j=1;j<t;j++)
        {
        	maxv=Math.max(maxv,r[j]-minv);
        	minv=Math.min(minv,r[j]);
        } j=1; j=1 j 1 j<t j t j++ j++ j {
        	maxv=Math.max(maxv,r[j]-minv);
        	minv=Math.min(minv,r[j]);
        } {
        	maxv=Math.max(maxv,r[j]-minv);
        	minv=Math.min(minv,r[j]);
        } maxv=Math.max(maxv,r[j]-minv) maxv Math.max(maxv,r[j]-minv) Math.max Math maxv r[j]-minv r[j] r j minv minv=Math.min(minv,r[j]) minv Math.min(minv,r[j]) Math.min Math minv r[j] r j System.out.println(maxv) System.out.println System.out System System.out maxv String[] args args public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
        int i,j,t,k,minv,maxv;
        Scanner scan=new Scanner(System.in);
        t=scan.nextInt();
        int r[]=new int[t+1];
        for(i=0;i<t;i++)
        {
        	r[i]=scan.nextInt();
        }
        minv=r[0];
        maxv=r[1]-r[0];
        for(j=1;j<t;j++)
        {
        	maxv=Math.max(maxv,r[j]-minv);
        	minv=Math.min(minv,r[j]);
        }
        System.out.println(maxv);
	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
        int i,j,t,k,minv,maxv;
        Scanner scan=new Scanner(System.in);
        t=scan.nextInt();
        int r[]=new int[t+1];
        for(i=0;i<t;i++)
        {
        	r[i]=scan.nextInt();
        }
        minv=r[0];
        maxv=r[1]-r[0];
        for(j=1;j<t;j++)
        {
        	maxv=Math.max(maxv,r[j]-minv);
        	minv=Math.min(minv,r[j]);
        }
        System.out.println(maxv);
	}

} Main
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
        int i,j,t,k,minv,maxv;
        Scanner scan=new Scanner(System.in);
        t=scan.nextInt();
        int r[]=new int[t+1];
        for(i=0;i<t;i++)
        {
        	r[i]=scan.nextInt();
        }
        minv=r[0];
        maxv=r[1]-r[0];
        for(j=1;j<t;j++)
        {
        	maxv=Math.max(maxv,r[j]-minv);
        	minv=Math.min(minv,r[j]);
        }
        System.out.println(maxv);
	}

}