import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        ArrayList<Integer> data = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            data.add(sc.nextInt());
        }
        sc.close();
        
        int min = data.get(0);
        int max = data.get(0);
        int ans = Integer.MIN_VALUE;
        int min_profit = Integer.MIN_VALUE;
        int count = 0;
        for (int num : data) {
            if (min > num) {
                min = num;

                if (min_profit <  min - max) {
                    min_profit = min - max;
                    max = min;
                } else {
                    max = Integer.MIN_VALUE;
                }
            } else if (count > 0 && max <= num) {
                max = num;
                if (ans < max - min)
                    ans = max - min;
            }
            count++;
       }
        System.out.println(ans > min_profit ? ans : min_profit);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        ArrayList<Integer> data = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            data.add(sc.nextInt());
        }
        sc.close();
        
        int min = data.get(0);
        int max = data.get(0);
        int ans = Integer.MIN_VALUE;
        int min_profit = Integer.MIN_VALUE;
        int count = 0;
        for (int num : data) {
            if (min > num) {
                min = num;

                if (min_profit <  min - max) {
                    min_profit = min - max;
                    max = min;
                } else {
                    max = Integer.MIN_VALUE;
                }
            } else if (count > 0 && max <= num) {
                max = num;
                if (ans < max - min)
                    ans = max - min;
            }
            count++;
       }
        System.out.println(ans > min_profit ? ans : min_profit);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        ArrayList<Integer> data = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            data.add(sc.nextInt());
        }
        sc.close();
        
        int min = data.get(0);
        int max = data.get(0);
        int ans = Integer.MIN_VALUE;
        int min_profit = Integer.MIN_VALUE;
        int count = 0;
        for (int num : data) {
            if (min > num) {
                min = num;

                if (min_profit <  min - max) {
                    min_profit = min - max;
                    max = min;
                } else {
                    max = Integer.MIN_VALUE;
                }
            } else if (count > 0 && max <= num) {
                max = num;
                if (ans < max - min)
                    ans = max - min;
            }
            count++;
       }
        System.out.println(ans > min_profit ? ans : min_profit);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        ArrayList<Integer> data = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            data.add(sc.nextInt());
        }
        sc.close();
        
        int min = data.get(0);
        int max = data.get(0);
        int ans = Integer.MIN_VALUE;
        int min_profit = Integer.MIN_VALUE;
        int count = 0;
        for (int num : data) {
            if (min > num) {
                min = num;

                if (min_profit <  min - max) {
                    min_profit = min - max;
                    max = min;
                } else {
                    max = Integer.MIN_VALUE;
                }
            } else if (count > 0 && max <= num) {
                max = num;
                if (ans < max - min)
                    ans = max - min;
            }
            count++;
       }
        System.out.println(ans > min_profit ? ans : min_profit);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc ArrayList<Integer> data = new ArrayList<Integer>(); data new ArrayList<Integer>() for (int i = 0; i < n; i++) {
            data.add(sc.nextInt());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            data.add(sc.nextInt());
        } {
            data.add(sc.nextInt());
        } data.add(sc.nextInt()) data.add data sc.nextInt() sc.nextInt sc sc.close() sc.close sc int min = data.get(0); min data.get(0) data.get data 0 int max = data.get(0); max data.get(0) data.get data 0 int ans = Integer.MIN_VALUE; ans Integer.MIN_VALUE Integer Integer.MIN_VALUE int min_profit = Integer.MIN_VALUE; min_profit Integer.MIN_VALUE Integer Integer.MIN_VALUE int count = 0; count 0 for (int num : data) {
            if (min > num) {
                min = num;

                if (min_profit <  min - max) {
                    min_profit = min - max;
                    max = min;
                } else {
                    max = Integer.MIN_VALUE;
                }
            } else if (count > 0 && max <= num) {
                max = num;
                if (ans < max - min)
                    ans = max - min;
            }
            count++;
       } int num data {
            if (min > num) {
                min = num;

                if (min_profit <  min - max) {
                    min_profit = min - max;
                    max = min;
                } else {
                    max = Integer.MIN_VALUE;
                }
            } else if (count > 0 && max <= num) {
                max = num;
                if (ans < max - min)
                    ans = max - min;
            }
            count++;
       } {
            if (min > num) {
                min = num;

                if (min_profit <  min - max) {
                    min_profit = min - max;
                    max = min;
                } else {
                    max = Integer.MIN_VALUE;
                }
            } else if (count > 0 && max <= num) {
                max = num;
                if (ans < max - min)
                    ans = max - min;
            }
            count++;
       } if (min > num) {
                min = num;

                if (min_profit <  min - max) {
                    min_profit = min - max;
                    max = min;
                } else {
                    max = Integer.MIN_VALUE;
                }
            } else if (count > 0 && max <= num) {
                max = num;
                if (ans < max - min)
                    ans = max - min;
            } min > num min num {
                min = num;

                if (min_profit <  min - max) {
                    min_profit = min - max;
                    max = min;
                } else {
                    max = Integer.MIN_VALUE;
                }
            } min = num min num if (min_profit <  min - max) {
                    min_profit = min - max;
                    max = min;
                } else {
                    max = Integer.MIN_VALUE;
                } min_profit <  min - max min_profit min - max min max {
                    min_profit = min - max;
                    max = min;
                } min_profit = min - max min_profit min - max min max max = min max min {
                    max = Integer.MIN_VALUE;
                } max = Integer.MIN_VALUE max Integer.MIN_VALUE Integer Integer.MIN_VALUE if (count > 0 && max <= num) {
                max = num;
                if (ans < max - min)
                    ans = max - min;
            } count > 0 && max <= num count > 0 count 0 max <= num max num {
                max = num;
                if (ans < max - min)
                    ans = max - min;
            } max = num max num if (ans < max - min)
                    ans = max - min; ans < max - min ans max - min max min ans = max - min ans max - min max min count++ count System.out.println(ans > min_profit ? ans : min_profit) System.out.println System.out System System.out ans > min_profit ? ans : min_profit ans > min_profit ans min_profit ans min_profit String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        ArrayList<Integer> data = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            data.add(sc.nextInt());
        }
        sc.close();
        
        int min = data.get(0);
        int max = data.get(0);
        int ans = Integer.MIN_VALUE;
        int min_profit = Integer.MIN_VALUE;
        int count = 0;
        for (int num : data) {
            if (min > num) {
                min = num;

                if (min_profit <  min - max) {
                    min_profit = min - max;
                    max = min;
                } else {
                    max = Integer.MIN_VALUE;
                }
            } else if (count > 0 && max <= num) {
                max = num;
                if (ans < max - min)
                    ans = max - min;
            }
            count++;
       }
        System.out.println(ans > min_profit ? ans : min_profit);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        ArrayList<Integer> data = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            data.add(sc.nextInt());
        }
        sc.close();
        
        int min = data.get(0);
        int max = data.get(0);
        int ans = Integer.MIN_VALUE;
        int min_profit = Integer.MIN_VALUE;
        int count = 0;
        for (int num : data) {
            if (min > num) {
                min = num;

                if (min_profit <  min - max) {
                    min_profit = min - max;
                    max = min;
                } else {
                    max = Integer.MIN_VALUE;
                }
            } else if (count > 0 && max <= num) {
                max = num;
                if (ans < max - min)
                    ans = max - min;
            }
            count++;
       }
        System.out.println(ans > min_profit ? ans : min_profit);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        ArrayList<Integer> data = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            data.add(sc.nextInt());
        }
        sc.close();
        
        int min = data.get(0);
        int max = data.get(0);
        int ans = Integer.MIN_VALUE;
        int min_profit = Integer.MIN_VALUE;
        int count = 0;
        for (int num : data) {
            if (min > num) {
                min = num;

                if (min_profit <  min - max) {
                    min_profit = min - max;
                    max = min;
                } else {
                    max = Integer.MIN_VALUE;
                }
            } else if (count > 0 && max <= num) {
                max = num;
                if (ans < max - min)
                    ans = max - min;
            }
            count++;
       }
        System.out.println(ans > min_profit ? ans : min_profit);
    }
}
