import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int max = 0;
		int min = 0;
		int prospectMin = 0;
		int beforeN = 0;
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(br.readLine());
			if (i == 0) {
				min = a;
				prospectMin = a;
				continue;
			}
			if (i == 1) {
				max = a;
				beforeN = a;
				if (a < min) {
					prospectMin = a;
				}
				continue;
			}
			if (beforeN <= a && max - min < a - prospectMin) {
				max = a;
				if (min > prospectMin) {
					min = prospectMin;
				}
			}
			if (a < prospectMin) {
				prospectMin = a;
			}
			beforeN = a;
		}
		System.out.println(max - min);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int max = 0;
		int min = 0;
		int prospectMin = 0;
		int beforeN = 0;
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(br.readLine());
			if (i == 0) {
				min = a;
				prospectMin = a;
				continue;
			}
			if (i == 1) {
				max = a;
				beforeN = a;
				if (a < min) {
					prospectMin = a;
				}
				continue;
			}
			if (beforeN <= a && max - min < a - prospectMin) {
				max = a;
				if (min > prospectMin) {
					min = prospectMin;
				}
			}
			if (a < prospectMin) {
				prospectMin = a;
			}
			beforeN = a;
		}
		System.out.println(max - min);
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int max = 0;
		int min = 0;
		int prospectMin = 0;
		int beforeN = 0;
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(br.readLine());
			if (i == 0) {
				min = a;
				prospectMin = a;
				continue;
			}
			if (i == 1) {
				max = a;
				beforeN = a;
				if (a < min) {
					prospectMin = a;
				}
				continue;
			}
			if (beforeN <= a && max - min < a - prospectMin) {
				max = a;
				if (min > prospectMin) {
					min = prospectMin;
				}
			}
			if (a < prospectMin) {
				prospectMin = a;
			}
			beforeN = a;
		}
		System.out.println(max - min);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int max = 0;
		int min = 0;
		int prospectMin = 0;
		int beforeN = 0;
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(br.readLine());
			if (i == 0) {
				min = a;
				prospectMin = a;
				continue;
			}
			if (i == 1) {
				max = a;
				beforeN = a;
				if (a < min) {
					prospectMin = a;
				}
				continue;
			}
			if (beforeN <= a && max - min < a - prospectMin) {
				max = a;
				if (min > prospectMin) {
					min = prospectMin;
				}
			}
			if (a < prospectMin) {
				prospectMin = a;
			}
			beforeN = a;
		}
		System.out.println(max - min);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int max = 0; max 0 int min = 0; min 0 int prospectMin = 0; prospectMin 0 int beforeN = 0; beforeN 0 for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(br.readLine());
			if (i == 0) {
				min = a;
				prospectMin = a;
				continue;
			}
			if (i == 1) {
				max = a;
				beforeN = a;
				if (a < min) {
					prospectMin = a;
				}
				continue;
			}
			if (beforeN <= a && max - min < a - prospectMin) {
				max = a;
				if (min > prospectMin) {
					min = prospectMin;
				}
			}
			if (a < prospectMin) {
				prospectMin = a;
			}
			beforeN = a;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int a = Integer.parseInt(br.readLine());
			if (i == 0) {
				min = a;
				prospectMin = a;
				continue;
			}
			if (i == 1) {
				max = a;
				beforeN = a;
				if (a < min) {
					prospectMin = a;
				}
				continue;
			}
			if (beforeN <= a && max - min < a - prospectMin) {
				max = a;
				if (min > prospectMin) {
					min = prospectMin;
				}
			}
			if (a < prospectMin) {
				prospectMin = a;
			}
			beforeN = a;
		} {
			int a = Integer.parseInt(br.readLine());
			if (i == 0) {
				min = a;
				prospectMin = a;
				continue;
			}
			if (i == 1) {
				max = a;
				beforeN = a;
				if (a < min) {
					prospectMin = a;
				}
				continue;
			}
			if (beforeN <= a && max - min < a - prospectMin) {
				max = a;
				if (min > prospectMin) {
					min = prospectMin;
				}
			}
			if (a < prospectMin) {
				prospectMin = a;
			}
			beforeN = a;
		} int a = Integer.parseInt(br.readLine()); a Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br if (i == 0) {
				min = a;
				prospectMin = a;
				continue;
			} i == 0 i 0 {
				min = a;
				prospectMin = a;
				continue;
			} min = a min a prospectMin = a prospectMin a continue; if (i == 1) {
				max = a;
				beforeN = a;
				if (a < min) {
					prospectMin = a;
				}
				continue;
			} i == 1 i 1 {
				max = a;
				beforeN = a;
				if (a < min) {
					prospectMin = a;
				}
				continue;
			} max = a max a beforeN = a beforeN a if (a < min) {
					prospectMin = a;
				} a < min a min {
					prospectMin = a;
				} prospectMin = a prospectMin a continue; if (beforeN <= a && max - min < a - prospectMin) {
				max = a;
				if (min > prospectMin) {
					min = prospectMin;
				}
			} beforeN <= a && max - min < a - prospectMin beforeN <= a beforeN a max - min < a - prospectMin max - min max min a - prospectMin a prospectMin {
				max = a;
				if (min > prospectMin) {
					min = prospectMin;
				}
			} max = a max a if (min > prospectMin) {
					min = prospectMin;
				} min > prospectMin min prospectMin {
					min = prospectMin;
				} min = prospectMin min prospectMin if (a < prospectMin) {
				prospectMin = a;
			} a < prospectMin a prospectMin {
				prospectMin = a;
			} prospectMin = a prospectMin a beforeN = a beforeN a System.out.println(max - min) System.out.println System.out System System.out max - min max min String[] args args public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int max = 0;
		int min = 0;
		int prospectMin = 0;
		int beforeN = 0;
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(br.readLine());
			if (i == 0) {
				min = a;
				prospectMin = a;
				continue;
			}
			if (i == 1) {
				max = a;
				beforeN = a;
				if (a < min) {
					prospectMin = a;
				}
				continue;
			}
			if (beforeN <= a && max - min < a - prospectMin) {
				max = a;
				if (min > prospectMin) {
					min = prospectMin;
				}
			}
			if (a < prospectMin) {
				prospectMin = a;
			}
			beforeN = a;
		}
		System.out.println(max - min);
	}
} public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int max = 0;
		int min = 0;
		int prospectMin = 0;
		int beforeN = 0;
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(br.readLine());
			if (i == 0) {
				min = a;
				prospectMin = a;
				continue;
			}
			if (i == 1) {
				max = a;
				beforeN = a;
				if (a < min) {
					prospectMin = a;
				}
				continue;
			}
			if (beforeN <= a && max - min < a - prospectMin) {
				max = a;
				if (min > prospectMin) {
					min = prospectMin;
				}
			}
			if (a < prospectMin) {
				prospectMin = a;
			}
			beforeN = a;
		}
		System.out.println(max - min);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int max = 0;
		int min = 0;
		int prospectMin = 0;
		int beforeN = 0;
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(br.readLine());
			if (i == 0) {
				min = a;
				prospectMin = a;
				continue;
			}
			if (i == 1) {
				max = a;
				beforeN = a;
				if (a < min) {
					prospectMin = a;
				}
				continue;
			}
			if (beforeN <= a && max - min < a - prospectMin) {
				max = a;
				if (min > prospectMin) {
					min = prospectMin;
				}
			}
			if (a < prospectMin) {
				prospectMin = a;
			}
			beforeN = a;
		}
		System.out.println(max - min);
	}
}