import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        
        int n = std.nextInt();
        int[] hs = new int[n];
        for (int i = 0; i < n; i++) {
            hs[i] = std.nextInt();
        }

        int v = 0;
        int e = 0;

        for (int i = 0; i < n; i++) {
            int h = hs[i];
            v += h;
        }

        for (int i = 1; i < n; i++) {
            e += Math.min(hs[i], hs[i - 1]);
        }

        System.out.println(v - e);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        
        int n = std.nextInt();
        int[] hs = new int[n];
        for (int i = 0; i < n; i++) {
            hs[i] = std.nextInt();
        }

        int v = 0;
        int e = 0;

        for (int i = 0; i < n; i++) {
            int h = hs[i];
            v += h;
        }

        for (int i = 1; i < n; i++) {
            e += Math.min(hs[i], hs[i - 1]);
        }

        System.out.println(v - e);
    }
} Main public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        
        int n = std.nextInt();
        int[] hs = new int[n];
        for (int i = 0; i < n; i++) {
            hs[i] = std.nextInt();
        }

        int v = 0;
        int e = 0;

        for (int i = 0; i < n; i++) {
            int h = hs[i];
            v += h;
        }

        for (int i = 1; i < n; i++) {
            e += Math.min(hs[i], hs[i - 1]);
        }

        System.out.println(v - e);
    } main {
        Scanner std = new Scanner(System.in);
        
        int n = std.nextInt();
        int[] hs = new int[n];
        for (int i = 0; i < n; i++) {
            hs[i] = std.nextInt();
        }

        int v = 0;
        int e = 0;

        for (int i = 0; i < n; i++) {
            int h = hs[i];
            v += h;
        }

        for (int i = 1; i < n; i++) {
            e += Math.min(hs[i], hs[i - 1]);
        }

        System.out.println(v - e);
    } Scanner std = new Scanner(System.in); std new Scanner(System.in) int n = std.nextInt(); n std.nextInt() std.nextInt std int[] hs = new int[n]; hs new int[n] n for (int i = 0; i < n; i++) {
            hs[i] = std.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            hs[i] = std.nextInt();
        } {
            hs[i] = std.nextInt();
        } hs[i] = std.nextInt() hs[i] hs i std.nextInt() std.nextInt std int v = 0; v 0 int e = 0; e 0 for (int i = 0; i < n; i++) {
            int h = hs[i];
            v += h;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int h = hs[i];
            v += h;
        } {
            int h = hs[i];
            v += h;
        } int h = hs[i]; h hs[i] hs i v += h v h for (int i = 1; i < n; i++) {
            e += Math.min(hs[i], hs[i - 1]);
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            e += Math.min(hs[i], hs[i - 1]);
        } {
            e += Math.min(hs[i], hs[i - 1]);
        } e += Math.min(hs[i], hs[i - 1]) e Math.min(hs[i], hs[i - 1]) Math.min Math hs[i] hs i hs[i - 1] hs i - 1 i 1 System.out.println(v - e) System.out.println System.out System System.out v - e v e String[] args args public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        
        int n = std.nextInt();
        int[] hs = new int[n];
        for (int i = 0; i < n; i++) {
            hs[i] = std.nextInt();
        }

        int v = 0;
        int e = 0;

        for (int i = 0; i < n; i++) {
            int h = hs[i];
            v += h;
        }

        for (int i = 1; i < n; i++) {
            e += Math.min(hs[i], hs[i - 1]);
        }

        System.out.println(v - e);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        
        int n = std.nextInt();
        int[] hs = new int[n];
        for (int i = 0; i < n; i++) {
            hs[i] = std.nextInt();
        }

        int v = 0;
        int e = 0;

        for (int i = 0; i < n; i++) {
            int h = hs[i];
            v += h;
        }

        for (int i = 1; i < n; i++) {
            e += Math.min(hs[i], hs[i - 1]);
        }

        System.out.println(v - e);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        
        int n = std.nextInt();
        int[] hs = new int[n];
        for (int i = 0; i < n; i++) {
            hs[i] = std.nextInt();
        }

        int v = 0;
        int e = 0;

        for (int i = 0; i < n; i++) {
            int h = hs[i];
            v += h;
        }

        for (int i = 1; i < n; i++) {
            e += Math.min(hs[i], hs[i - 1]);
        }

        System.out.println(v - e);
    }
}
