import java.util.Scanner;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] high = new int[N+1];
        for (int i = 1; i <= N; i++) {
            high[i] = sc.nextInt();
        }
        int tot = 0;
        int tmp = 0;
        for (int i = 1; i < N+1; i++) {
            if (tmp < high[i]) {
                tot += high[i]-tmp;
            }
            tmp = high[i];
        }
        System.out.println(tot);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] high = new int[N+1];
        for (int i = 1; i <= N; i++) {
            high[i] = sc.nextInt();
        }
        int tot = 0;
        int tmp = 0;
        for (int i = 1; i < N+1; i++) {
            if (tmp < high[i]) {
                tot += high[i]-tmp;
            }
            tmp = high[i];
        }
        System.out.println(tot);
    }
} Main public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] high = new int[N+1];
        for (int i = 1; i <= N; i++) {
            high[i] = sc.nextInt();
        }
        int tot = 0;
        int tmp = 0;
        for (int i = 1; i < N+1; i++) {
            if (tmp < high[i]) {
                tot += high[i]-tmp;
            }
            tmp = high[i];
        }
        System.out.println(tot);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] high = new int[N+1];
        for (int i = 1; i <= N; i++) {
            high[i] = sc.nextInt();
        }
        int tot = 0;
        int tmp = 0;
        for (int i = 1; i < N+1; i++) {
            if (tmp < high[i]) {
                tot += high[i]-tmp;
            }
            tmp = high[i];
        }
        System.out.println(tot);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] high = new int[N+1]; high new int[N+1] N+1 N 1 for (int i = 1; i <= N; i++) {
            high[i] = sc.nextInt();
        } int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
            high[i] = sc.nextInt();
        } {
            high[i] = sc.nextInt();
        } high[i] = sc.nextInt() high[i] high i sc.nextInt() sc.nextInt sc int tot = 0; tot 0 int tmp = 0; tmp 0 for (int i = 1; i < N+1; i++) {
            if (tmp < high[i]) {
                tot += high[i]-tmp;
            }
            tmp = high[i];
        } int i = 1; int i = 1; i 1 i < N+1 i N+1 N 1 i++ i++ i {
            if (tmp < high[i]) {
                tot += high[i]-tmp;
            }
            tmp = high[i];
        } {
            if (tmp < high[i]) {
                tot += high[i]-tmp;
            }
            tmp = high[i];
        } if (tmp < high[i]) {
                tot += high[i]-tmp;
            } tmp < high[i] tmp high[i] high i {
                tot += high[i]-tmp;
            } tot += high[i]-tmp tot high[i]-tmp high[i] high i tmp tmp = high[i] tmp high[i] high i System.out.println(tot) System.out.println System.out System System.out tot String args[] args public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] high = new int[N+1];
        for (int i = 1; i <= N; i++) {
            high[i] = sc.nextInt();
        }
        int tot = 0;
        int tmp = 0;
        for (int i = 1; i < N+1; i++) {
            if (tmp < high[i]) {
                tot += high[i]-tmp;
            }
            tmp = high[i];
        }
        System.out.println(tot);
    }
} public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] high = new int[N+1];
        for (int i = 1; i <= N; i++) {
            high[i] = sc.nextInt();
        }
        int tot = 0;
        int tmp = 0;
        for (int i = 1; i < N+1; i++) {
            if (tmp < high[i]) {
                tot += high[i]-tmp;
            }
            tmp = high[i];
        }
        System.out.println(tot);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] high = new int[N+1];
        for (int i = 1; i <= N; i++) {
            high[i] = sc.nextInt();
        }
        int tot = 0;
        int tmp = 0;
        for (int i = 1; i < N+1; i++) {
            if (tmp < high[i]) {
                tot += high[i]-tmp;
            }
            tmp = high[i];
        }
        System.out.println(tot);
    }
}