import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
 
public class Main {
	public void exec() throws IOException {
        InputUtil in = new InputUtil();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int min=200000,max=1,maxRtDiff=-1000000000;
        boolean first = true;
        for(int rt: in.nextInt(new int[n])){
        	if(first) {
        		min = rt;
        		max = 1;
        		first = false;
        	}else{
            	if(max < rt) {
            		max = rt;
            	}
        		int rtDiff = max - min;
        		if(maxRtDiff < rtDiff) {
        			maxRtDiff = rtDiff;
        		}
            	if(rt < min) {
            		min = rt;
            		max = 1;
            	}
        	}
        }
        out.println(maxRtDiff);
        out.flush();
    }

    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
}


/**
 * --------------------------------------------------
 * Input Utility
 * --------------------------------------------------
 */
class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 50000;
	
	//Fields
	protected InputStream in;
	private char[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private BufferedReader br = null;
	
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {br = new BufferedReader(new InputStreamReader(this.in = in));}
	protected void initBuf(int bufsiz) {buf = new char[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && br.ready()) {
			max = br.read(buf);
			ptr = 0;
		}
	}
	//Number Input Reader/Parser
	private boolean isNum(char b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(char b) {return b=='-'; }

	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		char c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}

	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.PrintWriter; PrintWriter java.io public class Main {
	public void exec() throws IOException {
        InputUtil in = new InputUtil();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int min=200000,max=1,maxRtDiff=-1000000000;
        boolean first = true;
        for(int rt: in.nextInt(new int[n])){
        	if(first) {
        		min = rt;
        		max = 1;
        		first = false;
        	}else{
            	if(max < rt) {
            		max = rt;
            	}
        		int rtDiff = max - min;
        		if(maxRtDiff < rtDiff) {
        			maxRtDiff = rtDiff;
        		}
            	if(rt < min) {
            		min = rt;
            		max = 1;
            	}
        	}
        }
        out.println(maxRtDiff);
        out.flush();
    }

    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
} Main public void exec() throws IOException {
        InputUtil in = new InputUtil();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int min=200000,max=1,maxRtDiff=-1000000000;
        boolean first = true;
        for(int rt: in.nextInt(new int[n])){
        	if(first) {
        		min = rt;
        		max = 1;
        		first = false;
        	}else{
            	if(max < rt) {
            		max = rt;
            	}
        		int rtDiff = max - min;
        		if(maxRtDiff < rtDiff) {
        			maxRtDiff = rtDiff;
        		}
            	if(rt < min) {
            		min = rt;
            		max = 1;
            	}
        	}
        }
        out.println(maxRtDiff);
        out.flush();
    } exec {
        InputUtil in = new InputUtil();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int min=200000,max=1,maxRtDiff=-1000000000;
        boolean first = true;
        for(int rt: in.nextInt(new int[n])){
        	if(first) {
        		min = rt;
        		max = 1;
        		first = false;
        	}else{
            	if(max < rt) {
            		max = rt;
            	}
        		int rtDiff = max - min;
        		if(maxRtDiff < rtDiff) {
        			maxRtDiff = rtDiff;
        		}
            	if(rt < min) {
            		min = rt;
            		max = 1;
            	}
        	}
        }
        out.println(maxRtDiff);
        out.flush();
    } InputUtil in = new InputUtil(); in new InputUtil() PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) int n = in.nextInt(); n in.nextInt() in.nextInt in int min=200000 min 200000 max=1 max 1 maxRtDiff=-1000000000; maxRtDiff -1000000000 1000000000 boolean first = true; first true for(int rt: in.nextInt(new int[n])){
        	if(first) {
        		min = rt;
        		max = 1;
        		first = false;
        	}else{
            	if(max < rt) {
            		max = rt;
            	}
        		int rtDiff = max - min;
        		if(maxRtDiff < rtDiff) {
        			maxRtDiff = rtDiff;
        		}
            	if(rt < min) {
            		min = rt;
            		max = 1;
            	}
        	}
        } int rt in.nextInt(new int[n]) in.nextInt in new int[n] n {
        	if(first) {
        		min = rt;
        		max = 1;
        		first = false;
        	}else{
            	if(max < rt) {
            		max = rt;
            	}
        		int rtDiff = max - min;
        		if(maxRtDiff < rtDiff) {
        			maxRtDiff = rtDiff;
        		}
            	if(rt < min) {
            		min = rt;
            		max = 1;
            	}
        	}
        } {
        	if(first) {
        		min = rt;
        		max = 1;
        		first = false;
        	}else{
            	if(max < rt) {
            		max = rt;
            	}
        		int rtDiff = max - min;
        		if(maxRtDiff < rtDiff) {
        			maxRtDiff = rtDiff;
        		}
            	if(rt < min) {
            		min = rt;
            		max = 1;
            	}
        	}
        } if(first) {
        		min = rt;
        		max = 1;
        		first = false;
        	}else{
            	if(max < rt) {
            		max = rt;
            	}
        		int rtDiff = max - min;
        		if(maxRtDiff < rtDiff) {
        			maxRtDiff = rtDiff;
        		}
            	if(rt < min) {
            		min = rt;
            		max = 1;
            	}
        	} first {
        		min = rt;
        		max = 1;
        		first = false;
        	} min = rt min rt max = 1 max 1 first = false first false {
            	if(max < rt) {
            		max = rt;
            	}
        		int rtDiff = max - min;
        		if(maxRtDiff < rtDiff) {
        			maxRtDiff = rtDiff;
        		}
            	if(rt < min) {
            		min = rt;
            		max = 1;
            	}
        	} if(max < rt) {
            		max = rt;
            	} max < rt max rt {
            		max = rt;
            	} max = rt max rt int rtDiff = max - min; rtDiff max - min max min if(maxRtDiff < rtDiff) {
        			maxRtDiff = rtDiff;
        		} maxRtDiff < rtDiff maxRtDiff rtDiff {
        			maxRtDiff = rtDiff;
        		} maxRtDiff = rtDiff maxRtDiff rtDiff if(rt < min) {
            		min = rt;
            		max = 1;
            	} rt < min rt min {
            		min = rt;
            		max = 1;
            	} min = rt min rt max = 1 max 1 out.println(maxRtDiff) out.println out maxRtDiff out.flush() out.flush out public static void main(String[] args) throws IOException {
        new Main().exec();
    } main {
        new Main().exec();
    } new Main().exec() new Main().exec new Main() String[] args args class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 50000;
	
	//Fields
	protected InputStream in;
	private char[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private BufferedReader br = null;
	
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {br = new BufferedReader(new InputStreamReader(this.in = in));}
	protected void initBuf(int bufsiz) {buf = new char[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && br.ready()) {
			max = br.read(buf);
			ptr = 0;
		}
	}
	//Number Input Reader/Parser
	private boolean isNum(char b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(char b) {return b=='-'; }

	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		char c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}

	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}

} InputUtil //Static Fields
	private static final int BUFSIZ = 50000; BUFSIZ 50000 //Fields
	protected InputStream in; in private char[] buf = null; buf null private int ptr = 0; ptr 0 private int max = -1; max -1 1 private BufferedReader br = null; br null //Constructors
	public InputUtil() {this(System.in,BUFSIZ);} InputUtil {this(System.in,BUFSIZ);} this(System.in,BUFSIZ) this System.in System System.in BUFSIZ public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	} InputUtil {
		initBuf(bufsiz);
		initIn(in);
	} initBuf(bufsiz) initBuf bufsiz initIn(in) initIn in InputStream in in int bufsiz bufsiz //Methods
	//Initializer
	protected void initIn(InputStream in) {br = new BufferedReader(new InputStreamReader(this.in = in));} initIn {br = new BufferedReader(new InputStreamReader(this.in = in));} br = new BufferedReader(new InputStreamReader(this.in = in)) br new BufferedReader(new InputStreamReader(this.in = in)) InputStream in in protected void initBuf(int bufsiz) {buf = new char[bufsiz];} initBuf {buf = new char[bufsiz];} buf = new char[bufsiz] buf new char[bufsiz] bufsiz int bufsiz bufsiz //buffer operation
	private void next() throws IOException {ptr++; readBuf();} next {ptr++; readBuf();} ptr++ ptr readBuf() readBuf private void readBuf() throws IOException {
		if(ptr >= max && br.ready()) {
			max = br.read(buf);
			ptr = 0;
		}
	} readBuf {
		if(ptr >= max && br.ready()) {
			max = br.read(buf);
			ptr = 0;
		}
	} if(ptr >= max && br.ready()) {
			max = br.read(buf);
			ptr = 0;
		} ptr >= max && br.ready() ptr >= max ptr max br.ready() br.ready br {
			max = br.read(buf);
			ptr = 0;
		} max = br.read(buf) max br.read(buf) br.read br buf ptr = 0 ptr 0 //Number Input Reader/Parser
	private boolean isNum(char b) {return '0' <= b && b <= '9'; } isNum {return '0' <= b && b <= '9'; } return '0' <= b && b <= '9'; '0' <= b && b <= '9' '0' <= b '0' b b <= '9' b '9' char b b private boolean isMinus(char b) {return b=='-'; } isMinus {return b=='-'; } return b=='-'; b=='-' b '-' char b b private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		char c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	} _nextInt {
		int sign = 1;
		int res = 0;
		char c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	} int sign = 1; sign 1 int res = 0; res 0 char c; c while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next(); !isNum(c=buf[ptr]) && !isMinus(c) !isNum(c=buf[ptr]) isNum(c=buf[ptr]) isNum c=buf[ptr] c buf[ptr] buf ptr !isMinus(c) isMinus(c) isMinus c next() next if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		} isMinus(buf[ptr]) isMinus buf[ptr] buf ptr {
			sign = -1;
			next();
		} sign = -1 sign -1 1 next() next while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		} isNum(c=buf[ptr]) isNum c=buf[ptr] c buf[ptr] buf ptr {
			res *= 10;
			res += c - '0' ;
			next();
		} res *= 10 res 10 res += c - '0' res c - '0' c '0' next() next next() next return sign * res; sign * res sign res public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	} nextInt {
		readBuf();
		return _nextInt();
	} readBuf() readBuf return _nextInt(); _nextInt() _nextInt public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	} nextInt {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	} readBuf() readBuf for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		} int i=0; int i=0; i 0 i<result.length i result.length result result.length i++ i++ i {
			result[i] = _nextInt();
		} {
			result[i] = _nextInt();
		} result[i] = _nextInt() result[i] result i _nextInt() _nextInt return result; result int[] result result //Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	} close {
		if(!this.in.equals(System.in)) 
			this.in.close();
	} if(!this.in.equals(System.in)) 
			this.in.close(); !this.in.equals(System.in) this.in.equals(System.in) this.in.equals this.in this this.in System.in System System.in this.in.close() this.in.close this.in this this.in public class Main {
	public void exec() throws IOException {
        InputUtil in = new InputUtil();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int min=200000,max=1,maxRtDiff=-1000000000;
        boolean first = true;
        for(int rt: in.nextInt(new int[n])){
        	if(first) {
        		min = rt;
        		max = 1;
        		first = false;
        	}else{
            	if(max < rt) {
            		max = rt;
            	}
        		int rtDiff = max - min;
        		if(maxRtDiff < rtDiff) {
        			maxRtDiff = rtDiff;
        		}
            	if(rt < min) {
            		min = rt;
            		max = 1;
            	}
        	}
        }
        out.println(maxRtDiff);
        out.flush();
    }

    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
} public class Main {
	public void exec() throws IOException {
        InputUtil in = new InputUtil();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int min=200000,max=1,maxRtDiff=-1000000000;
        boolean first = true;
        for(int rt: in.nextInt(new int[n])){
        	if(first) {
        		min = rt;
        		max = 1;
        		first = false;
        	}else{
            	if(max < rt) {
            		max = rt;
            	}
        		int rtDiff = max - min;
        		if(maxRtDiff < rtDiff) {
        			maxRtDiff = rtDiff;
        		}
            	if(rt < min) {
            		min = rt;
            		max = 1;
            	}
        	}
        }
        out.println(maxRtDiff);
        out.flush();
    }

    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
 
public class Main {
	public void exec() throws IOException {
        InputUtil in = new InputUtil();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int min=200000,max=1,maxRtDiff=-1000000000;
        boolean first = true;
        for(int rt: in.nextInt(new int[n])){
        	if(first) {
        		min = rt;
        		max = 1;
        		first = false;
        	}else{
            	if(max < rt) {
            		max = rt;
            	}
        		int rtDiff = max - min;
        		if(maxRtDiff < rtDiff) {
        			maxRtDiff = rtDiff;
        		}
            	if(rt < min) {
            		min = rt;
            		max = 1;
            	}
        	}
        }
        out.println(maxRtDiff);
        out.flush();
    }

    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
}


/**
 * --------------------------------------------------
 * Input Utility
 * --------------------------------------------------
 */
class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 50000;
	
	//Fields
	protected InputStream in;
	private char[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private BufferedReader br = null;
	
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {br = new BufferedReader(new InputStreamReader(this.in = in));}
	protected void initBuf(int bufsiz) {buf = new char[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && br.ready()) {
			max = br.read(buf);
			ptr = 0;
		}
	}
	//Number Input Reader/Parser
	private boolean isNum(char b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(char b) {return b=='-'; }

	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		char c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}

	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}

}