import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] x = new long[n];
        for(int i = 0; i < n; i++){
            x[i] = sc.nextLong();
        }
        long ans = 0;
        boolean isZero = false;
        while(!isZero){
            isZero = true;
            long prev = 0;
            for(int i = 0; i < n; i++){
                if(prev <= 0 && x[i] > 0){
                    ans++;
                    isZero = false;
                    prev = x[i];
                    x[i]--;
                }else if (prev > 0 && x[i] > 0){
                    prev = x[i];
                    x[i]--;
                }else{
                    prev = x[i];
                }
                
            }
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] x = new long[n];
        for(int i = 0; i < n; i++){
            x[i] = sc.nextLong();
        }
        long ans = 0;
        boolean isZero = false;
        while(!isZero){
            isZero = true;
            long prev = 0;
            for(int i = 0; i < n; i++){
                if(prev <= 0 && x[i] > 0){
                    ans++;
                    isZero = false;
                    prev = x[i];
                    x[i]--;
                }else if (prev > 0 && x[i] > 0){
                    prev = x[i];
                    x[i]--;
                }else{
                    prev = x[i];
                }
                
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] x = new long[n];
        for(int i = 0; i < n; i++){
            x[i] = sc.nextLong();
        }
        long ans = 0;
        boolean isZero = false;
        while(!isZero){
            isZero = true;
            long prev = 0;
            for(int i = 0; i < n; i++){
                if(prev <= 0 && x[i] > 0){
                    ans++;
                    isZero = false;
                    prev = x[i];
                    x[i]--;
                }else if (prev > 0 && x[i] > 0){
                    prev = x[i];
                    x[i]--;
                }else{
                    prev = x[i];
                }
                
            }
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] x = new long[n];
        for(int i = 0; i < n; i++){
            x[i] = sc.nextLong();
        }
        long ans = 0;
        boolean isZero = false;
        while(!isZero){
            isZero = true;
            long prev = 0;
            for(int i = 0; i < n; i++){
                if(prev <= 0 && x[i] > 0){
                    ans++;
                    isZero = false;
                    prev = x[i];
                    x[i]--;
                }else if (prev > 0 && x[i] > 0){
                    prev = x[i];
                    x[i]--;
                }else{
                    prev = x[i];
                }
                
            }
        }
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc long[] x = new long[n]; x new long[n] n for(int i = 0; i < n; i++){
            x[i] = sc.nextLong();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            x[i] = sc.nextLong();
        } {
            x[i] = sc.nextLong();
        } x[i] = sc.nextLong() x[i] x i sc.nextLong() sc.nextLong sc long ans = 0; ans 0 boolean isZero = false; isZero false while(!isZero){
            isZero = true;
            long prev = 0;
            for(int i = 0; i < n; i++){
                if(prev <= 0 && x[i] > 0){
                    ans++;
                    isZero = false;
                    prev = x[i];
                    x[i]--;
                }else if (prev > 0 && x[i] > 0){
                    prev = x[i];
                    x[i]--;
                }else{
                    prev = x[i];
                }
                
            }
        } !isZero isZero {
            isZero = true;
            long prev = 0;
            for(int i = 0; i < n; i++){
                if(prev <= 0 && x[i] > 0){
                    ans++;
                    isZero = false;
                    prev = x[i];
                    x[i]--;
                }else if (prev > 0 && x[i] > 0){
                    prev = x[i];
                    x[i]--;
                }else{
                    prev = x[i];
                }
                
            }
        } isZero = true isZero true long prev = 0; prev 0 for(int i = 0; i < n; i++){
                if(prev <= 0 && x[i] > 0){
                    ans++;
                    isZero = false;
                    prev = x[i];
                    x[i]--;
                }else if (prev > 0 && x[i] > 0){
                    prev = x[i];
                    x[i]--;
                }else{
                    prev = x[i];
                }
                
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if(prev <= 0 && x[i] > 0){
                    ans++;
                    isZero = false;
                    prev = x[i];
                    x[i]--;
                }else if (prev > 0 && x[i] > 0){
                    prev = x[i];
                    x[i]--;
                }else{
                    prev = x[i];
                }
                
            } {
                if(prev <= 0 && x[i] > 0){
                    ans++;
                    isZero = false;
                    prev = x[i];
                    x[i]--;
                }else if (prev > 0 && x[i] > 0){
                    prev = x[i];
                    x[i]--;
                }else{
                    prev = x[i];
                }
                
            } if(prev <= 0 && x[i] > 0){
                    ans++;
                    isZero = false;
                    prev = x[i];
                    x[i]--;
                }else if (prev > 0 && x[i] > 0){
                    prev = x[i];
                    x[i]--;
                }else{
                    prev = x[i];
                } prev <= 0 && x[i] > 0 prev <= 0 prev 0 x[i] > 0 x[i] x i 0 {
                    ans++;
                    isZero = false;
                    prev = x[i];
                    x[i]--;
                } ans++ ans isZero = false isZero false prev = x[i] prev x[i] x i x[i]-- x[i] x i if (prev > 0 && x[i] > 0){
                    prev = x[i];
                    x[i]--;
                }else{
                    prev = x[i];
                } prev > 0 && x[i] > 0 prev > 0 prev 0 x[i] > 0 x[i] x i 0 {
                    prev = x[i];
                    x[i]--;
                } prev = x[i] prev x[i] x i x[i]-- x[i] x i {
                    prev = x[i];
                } prev = x[i] prev x[i] x 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) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] x = new long[n];
        for(int i = 0; i < n; i++){
            x[i] = sc.nextLong();
        }
        long ans = 0;
        boolean isZero = false;
        while(!isZero){
            isZero = true;
            long prev = 0;
            for(int i = 0; i < n; i++){
                if(prev <= 0 && x[i] > 0){
                    ans++;
                    isZero = false;
                    prev = x[i];
                    x[i]--;
                }else if (prev > 0 && x[i] > 0){
                    prev = x[i];
                    x[i]--;
                }else{
                    prev = x[i];
                }
                
            }
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] x = new long[n];
        for(int i = 0; i < n; i++){
            x[i] = sc.nextLong();
        }
        long ans = 0;
        boolean isZero = false;
        while(!isZero){
            isZero = true;
            long prev = 0;
            for(int i = 0; i < n; i++){
                if(prev <= 0 && x[i] > 0){
                    ans++;
                    isZero = false;
                    prev = x[i];
                    x[i]--;
                }else if (prev > 0 && x[i] > 0){
                    prev = x[i];
                    x[i]--;
                }else{
                    prev = x[i];
                }
                
            }
        }
        System.out.println(ans);
    }
} Main
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] x = new long[n];
        for(int i = 0; i < n; i++){
            x[i] = sc.nextLong();
        }
        long ans = 0;
        boolean isZero = false;
        while(!isZero){
            isZero = true;
            long prev = 0;
            for(int i = 0; i < n; i++){
                if(prev <= 0 && x[i] > 0){
                    ans++;
                    isZero = false;
                    prev = x[i];
                    x[i]--;
                }else if (prev > 0 && x[i] > 0){
                    prev = x[i];
                    x[i]--;
                }else{
                    prev = x[i];
                }
                
            }
        }
        System.out.println(ans);
    }
}
