import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] H = new int[N];
        for(int i = 0;i < N;i++)    H[i] = sc.nextInt();
        int id = 0;
        int ans = 0;
        boolean f = false;
        while(true){
            f = false;
            for(int i = 0;i < N;i++){
                if(H[i] > 0){
                    f = true;
                    ans++;
                    while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    }
                }
            }
            if(!f)  break;
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] H = new int[N];
        for(int i = 0;i < N;i++)    H[i] = sc.nextInt();
        int id = 0;
        int ans = 0;
        boolean f = false;
        while(true){
            f = false;
            for(int i = 0;i < N;i++){
                if(H[i] > 0){
                    f = true;
                    ans++;
                    while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    }
                }
            }
            if(!f)  break;
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] H = new int[N];
        for(int i = 0;i < N;i++)    H[i] = sc.nextInt();
        int id = 0;
        int ans = 0;
        boolean f = false;
        while(true){
            f = false;
            for(int i = 0;i < N;i++){
                if(H[i] > 0){
                    f = true;
                    ans++;
                    while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    }
                }
            }
            if(!f)  break;
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] H = new int[N];
        for(int i = 0;i < N;i++)    H[i] = sc.nextInt();
        int id = 0;
        int ans = 0;
        boolean f = false;
        while(true){
            f = false;
            for(int i = 0;i < N;i++){
                if(H[i] > 0){
                    f = true;
                    ans++;
                    while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    }
                }
            }
            if(!f)  break;
        }
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] H = new int[N]; H new int[N] N for(int i = 0;i < N;i++)    H[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < N i N i++ i++ i H[i] = sc.nextInt(); H[i] = sc.nextInt() H[i] H i sc.nextInt() sc.nextInt sc int id = 0; id 0 int ans = 0; ans 0 boolean f = false; f false while(true){
            f = false;
            for(int i = 0;i < N;i++){
                if(H[i] > 0){
                    f = true;
                    ans++;
                    while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    }
                }
            }
            if(!f)  break;
        } true {
            f = false;
            for(int i = 0;i < N;i++){
                if(H[i] > 0){
                    f = true;
                    ans++;
                    while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    }
                }
            }
            if(!f)  break;
        } f = false f false for(int i = 0;i < N;i++){
                if(H[i] > 0){
                    f = true;
                    ans++;
                    while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    }
                }
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                if(H[i] > 0){
                    f = true;
                    ans++;
                    while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    }
                }
            } {
                if(H[i] > 0){
                    f = true;
                    ans++;
                    while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    }
                }
            } if(H[i] > 0){
                    f = true;
                    ans++;
                    while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    }
                } H[i] > 0 H[i] H i 0 {
                    f = true;
                    ans++;
                    while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    }
                } f = true f true ans++ ans while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    } H[i] > 0 H[i] H i 0 {
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    } H[i]-- H[i] H i i++ i if(i == N)    break; i == N i N break; if(!f)  break; !f f break; 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 sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] H = new int[N];
        for(int i = 0;i < N;i++)    H[i] = sc.nextInt();
        int id = 0;
        int ans = 0;
        boolean f = false;
        while(true){
            f = false;
            for(int i = 0;i < N;i++){
                if(H[i] > 0){
                    f = true;
                    ans++;
                    while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    }
                }
            }
            if(!f)  break;
        }
        System.out.println(ans);
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] H = new int[N];
        for(int i = 0;i < N;i++)    H[i] = sc.nextInt();
        int id = 0;
        int ans = 0;
        boolean f = false;
        while(true){
            f = false;
            for(int i = 0;i < N;i++){
                if(H[i] > 0){
                    f = true;
                    ans++;
                    while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    }
                }
            }
            if(!f)  break;
        }
        System.out.println(ans);
    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] H = new int[N];
        for(int i = 0;i < N;i++)    H[i] = sc.nextInt();
        int id = 0;
        int ans = 0;
        boolean f = false;
        while(true){
            f = false;
            for(int i = 0;i < N;i++){
                if(H[i] > 0){
                    f = true;
                    ans++;
                    while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    }
                }
            }
            if(!f)  break;
        }
        System.out.println(ans);
    }
}