import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        int count = 0;
        while(!isAllZero(h)) {
            int l = 0;
            int r = 1;
            while(l < n && h[l] == 0) l++;
            r = l + 1;
            while(r < n && h[r] != 0) r++;
            water(l, r, h);
            count++;
        }
        System.out.println(count);
    }
    private static boolean isAllZero(int[] h) {
        for(int i = 0; i < h.length; i++) {
            if(h[i] != 0) return false;
        }
        return true;
    }
    private static void water(int l, int r, int[] h) {
        while(l < h.length && l < r) {
            h[l]--;
            l++;
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        int count = 0;
        while(!isAllZero(h)) {
            int l = 0;
            int r = 1;
            while(l < n && h[l] == 0) l++;
            r = l + 1;
            while(r < n && h[r] != 0) r++;
            water(l, r, h);
            count++;
        }
        System.out.println(count);
    }
    private static boolean isAllZero(int[] h) {
        for(int i = 0; i < h.length; i++) {
            if(h[i] != 0) return false;
        }
        return true;
    }
    private static void water(int l, int r, int[] h) {
        while(l < h.length && l < r) {
            h[l]--;
            l++;
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        int count = 0;
        while(!isAllZero(h)) {
            int l = 0;
            int r = 1;
            while(l < n && h[l] == 0) l++;
            r = l + 1;
            while(r < n && h[r] != 0) r++;
            water(l, r, h);
            count++;
        }
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        int count = 0;
        while(!isAllZero(h)) {
            int l = 0;
            int r = 1;
            while(l < n && h[l] == 0) l++;
            r = l + 1;
            while(r < n && h[r] != 0) r++;
            water(l, r, h);
            count++;
        }
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) 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] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc int count = 0; count 0 while(!isAllZero(h)) {
            int l = 0;
            int r = 1;
            while(l < n && h[l] == 0) l++;
            r = l + 1;
            while(r < n && h[r] != 0) r++;
            water(l, r, h);
            count++;
        } !isAllZero(h) isAllZero(h) isAllZero h {
            int l = 0;
            int r = 1;
            while(l < n && h[l] == 0) l++;
            r = l + 1;
            while(r < n && h[r] != 0) r++;
            water(l, r, h);
            count++;
        } int l = 0; l 0 int r = 1; r 1 while(l < n && h[l] == 0) l++; l < n && h[l] == 0 l < n l n h[l] == 0 h[l] h l 0 l++ l r = l + 1 r l + 1 l 1 while(r < n && h[r] != 0) r++; r < n && h[r] != 0 r < n r n h[r] != 0 h[r] h r 0 r++ r water(l, r, h) water l r h count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args private static boolean isAllZero(int[] h) {
        for(int i = 0; i < h.length; i++) {
            if(h[i] != 0) return false;
        }
        return true;
    } isAllZero {
        for(int i = 0; i < h.length; i++) {
            if(h[i] != 0) return false;
        }
        return true;
    } for(int i = 0; i < h.length; i++) {
            if(h[i] != 0) return false;
        } int i = 0; int i = 0; i 0 i < h.length i h.length h h.length i++ i++ i {
            if(h[i] != 0) return false;
        } {
            if(h[i] != 0) return false;
        } if(h[i] != 0) return false; h[i] != 0 h[i] h i 0 return false; false return true; true int[] h h private static void water(int l, int r, int[] h) {
        while(l < h.length && l < r) {
            h[l]--;
            l++;
        }
    } water {
        while(l < h.length && l < r) {
            h[l]--;
            l++;
        }
    } while(l < h.length && l < r) {
            h[l]--;
            l++;
        } l < h.length && l < r l < h.length l h.length h h.length l < r l r {
            h[l]--;
            l++;
        } h[l]-- h[l] h l l++ l int l l int r r int[] h h public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        int count = 0;
        while(!isAllZero(h)) {
            int l = 0;
            int r = 1;
            while(l < n && h[l] == 0) l++;
            r = l + 1;
            while(r < n && h[r] != 0) r++;
            water(l, r, h);
            count++;
        }
        System.out.println(count);
    }
    private static boolean isAllZero(int[] h) {
        for(int i = 0; i < h.length; i++) {
            if(h[i] != 0) return false;
        }
        return true;
    }
    private static void water(int l, int r, int[] h) {
        while(l < h.length && l < r) {
            h[l]--;
            l++;
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        int count = 0;
        while(!isAllZero(h)) {
            int l = 0;
            int r = 1;
            while(l < n && h[l] == 0) l++;
            r = l + 1;
            while(r < n && h[r] != 0) r++;
            water(l, r, h);
            count++;
        }
        System.out.println(count);
    }
    private static boolean isAllZero(int[] h) {
        for(int i = 0; i < h.length; i++) {
            if(h[i] != 0) return false;
        }
        return true;
    }
    private static void water(int l, int r, int[] h) {
        while(l < h.length && l < r) {
            h[l]--;
            l++;
        }
    }
} Main
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        int count = 0;
        while(!isAllZero(h)) {
            int l = 0;
            int r = 1;
            while(l < n && h[l] == 0) l++;
            r = l + 1;
            while(r < n && h[r] != 0) r++;
            water(l, r, h);
            count++;
        }
        System.out.println(count);
    }
    private static boolean isAllZero(int[] h) {
        for(int i = 0; i < h.length; i++) {
            if(h[i] != 0) return false;
        }
        return true;
    }
    private static void water(int l, int r, int[] h) {
        while(l < h.length && l < r) {
            h[l]--;
            l++;
        }
    }
}
