import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int N = Integer.parseInt(s.next());
        int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(s.next());
        }

        int ans = 0;
        int active = 0;

        for (int i = 0; i < N; i++) {
            if (active >= h[i]) {
                active = h[i];
            } else {
                ans += h[i] - active;
                active = h[i];
            }
        }
        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int N = Integer.parseInt(s.next());
        int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(s.next());
        }

        int ans = 0;
        int active = 0;

        for (int i = 0; i < N; i++) {
            if (active >= h[i]) {
                active = h[i];
            } else {
                ans += h[i] - active;
                active = h[i];
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int N = Integer.parseInt(s.next());
        int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(s.next());
        }

        int ans = 0;
        int active = 0;

        for (int i = 0; i < N; i++) {
            if (active >= h[i]) {
                active = h[i];
            } else {
                ans += h[i] - active;
                active = h[i];
            }
        }
        System.out.println(ans);
    } main {
        Scanner s = new Scanner(System.in);

        int N = Integer.parseInt(s.next());
        int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(s.next());
        }

        int ans = 0;
        int active = 0;

        for (int i = 0; i < N; i++) {
            if (active >= h[i]) {
                active = h[i];
            } else {
                ans += h[i] - active;
                active = h[i];
            }
        }
        System.out.println(ans);
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int N = Integer.parseInt(s.next()); N Integer.parseInt(s.next()) Integer.parseInt Integer s.next() s.next s int[] h = new int[N]; h new int[N] N for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(s.next());
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            h[i] = Integer.parseInt(s.next());
        } {
            h[i] = Integer.parseInt(s.next());
        } h[i] = Integer.parseInt(s.next()) h[i] h i Integer.parseInt(s.next()) Integer.parseInt Integer s.next() s.next s int ans = 0; ans 0 int active = 0; active 0 for (int i = 0; i < N; i++) {
            if (active >= h[i]) {
                active = h[i];
            } else {
                ans += h[i] - active;
                active = h[i];
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (active >= h[i]) {
                active = h[i];
            } else {
                ans += h[i] - active;
                active = h[i];
            }
        } {
            if (active >= h[i]) {
                active = h[i];
            } else {
                ans += h[i] - active;
                active = h[i];
            }
        } if (active >= h[i]) {
                active = h[i];
            } else {
                ans += h[i] - active;
                active = h[i];
            } active >= h[i] active h[i] h i {
                active = h[i];
            } active = h[i] active h[i] h i {
                ans += h[i] - active;
                active = h[i];
            } ans += h[i] - active ans h[i] - active h[i] h i active active = h[i] active h[i] h i System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int N = Integer.parseInt(s.next());
        int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(s.next());
        }

        int ans = 0;
        int active = 0;

        for (int i = 0; i < N; i++) {
            if (active >= h[i]) {
                active = h[i];
            } else {
                ans += h[i] - active;
                active = h[i];
            }
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int N = Integer.parseInt(s.next());
        int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(s.next());
        }

        int ans = 0;
        int active = 0;

        for (int i = 0; i < N; i++) {
            if (active >= h[i]) {
                active = h[i];
            } else {
                ans += h[i] - active;
                active = h[i];
            }
        }
        System.out.println(ans);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int N = Integer.parseInt(s.next());
        int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(s.next());
        }

        int ans = 0;
        int active = 0;

        for (int i = 0; i < N; i++) {
            if (active >= h[i]) {
                active = h[i];
            } else {
                ans += h[i] - active;
                active = h[i];
            }
        }
        System.out.println(ans);
    }
}