import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Collections;
import java.awt.Point;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] s = br.readLine().split(" ");
        int[] h = new int[n];
        
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(s[i]);
        }
        
        int count = 0;
        boolean end = true; 
        boolean toCount = false;
        while (true) {
            end = true;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    end = false;
                    break;
                }
            }
            
            if (end) {
                break;
            }
            
            
            toCount = false;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    toCount = true;
                }
                else {
                    if (toCount) count++;
                    toCount = false;
                    continue;
                }
            }
            if (toCount) count++;
        }
        
        System.out.println(count);
    }
}
 import java.util.*; util.* java import java.io.InputStreamReader; InputStreamReader java.io import java.io.BufferedReader; BufferedReader java.io import java.util.Arrays; Arrays java.util import java.util.List; List java.util import java.util.ArrayList; ArrayList java.util import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util import java.util.Collections; Collections java.util import java.awt.Point; Point java.awt public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] s = br.readLine().split(" ");
        int[] h = new int[n];
        
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(s[i]);
        }
        
        int count = 0;
        boolean end = true; 
        boolean toCount = false;
        while (true) {
            end = true;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    end = false;
                    break;
                }
            }
            
            if (end) {
                break;
            }
            
            
            toCount = false;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    toCount = true;
                }
                else {
                    if (toCount) count++;
                    toCount = false;
                    continue;
                }
            }
            if (toCount) count++;
        }
        
        System.out.println(count);
    }
} Main public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] s = br.readLine().split(" ");
        int[] h = new int[n];
        
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(s[i]);
        }
        
        int count = 0;
        boolean end = true; 
        boolean toCount = false;
        while (true) {
            end = true;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    end = false;
                    break;
                }
            }
            
            if (end) {
                break;
            }
            
            
            toCount = false;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    toCount = true;
                }
                else {
                    if (toCount) count++;
                    toCount = false;
                    continue;
                }
            }
            if (toCount) count++;
        }
        
        System.out.println(count);
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] s = br.readLine().split(" ");
        int[] h = new int[n];
        
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(s[i]);
        }
        
        int count = 0;
        boolean end = true; 
        boolean toCount = false;
        while (true) {
            end = true;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    end = false;
                    break;
                }
            }
            
            if (end) {
                break;
            }
            
            
            toCount = false;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    toCount = true;
                }
                else {
                    if (toCount) count++;
                    toCount = false;
                    continue;
                }
            }
            if (toCount) count++;
        }
        
        System.out.println(count);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br String[] s = br.readLine().split(" "); s br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int[] h = new int[n]; h new int[n] n for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(s[i]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            h[i] = Integer.parseInt(s[i]);
        } {
            h[i] = Integer.parseInt(s[i]);
        } h[i] = Integer.parseInt(s[i]) h[i] h i Integer.parseInt(s[i]) Integer.parseInt Integer s[i] s i int count = 0; count 0 boolean end = true; end true boolean toCount = false; toCount false while (true) {
            end = true;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    end = false;
                    break;
                }
            }
            
            if (end) {
                break;
            }
            
            
            toCount = false;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    toCount = true;
                }
                else {
                    if (toCount) count++;
                    toCount = false;
                    continue;
                }
            }
            if (toCount) count++;
        } true {
            end = true;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    end = false;
                    break;
                }
            }
            
            if (end) {
                break;
            }
            
            
            toCount = false;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    toCount = true;
                }
                else {
                    if (toCount) count++;
                    toCount = false;
                    continue;
                }
            }
            if (toCount) count++;
        } end = true end true for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    end = false;
                    break;
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if (h[i] != 0) {
                    end = false;
                    break;
                }
            } {
                if (h[i] != 0) {
                    end = false;
                    break;
                }
            } if (h[i] != 0) {
                    end = false;
                    break;
                } h[i] != 0 h[i] h i 0 {
                    end = false;
                    break;
                } end = false end false break; if (end) {
                break;
            } end {
                break;
            } break; toCount = false toCount false for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    toCount = true;
                }
                else {
                    if (toCount) count++;
                    toCount = false;
                    continue;
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if (h[i] > 0) {
                    h[i]--;
                    toCount = true;
                }
                else {
                    if (toCount) count++;
                    toCount = false;
                    continue;
                }
            } {
                if (h[i] > 0) {
                    h[i]--;
                    toCount = true;
                }
                else {
                    if (toCount) count++;
                    toCount = false;
                    continue;
                }
            } if (h[i] > 0) {
                    h[i]--;
                    toCount = true;
                }
                else {
                    if (toCount) count++;
                    toCount = false;
                    continue;
                } h[i] > 0 h[i] h i 0 {
                    h[i]--;
                    toCount = true;
                } h[i]-- h[i] h i toCount = true toCount true {
                    if (toCount) count++;
                    toCount = false;
                    continue;
                } if (toCount) count++; toCount count++ count toCount = false toCount false continue; if (toCount) count++; toCount count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] s = br.readLine().split(" ");
        int[] h = new int[n];
        
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(s[i]);
        }
        
        int count = 0;
        boolean end = true; 
        boolean toCount = false;
        while (true) {
            end = true;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    end = false;
                    break;
                }
            }
            
            if (end) {
                break;
            }
            
            
            toCount = false;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    toCount = true;
                }
                else {
                    if (toCount) count++;
                    toCount = false;
                    continue;
                }
            }
            if (toCount) count++;
        }
        
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] s = br.readLine().split(" ");
        int[] h = new int[n];
        
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(s[i]);
        }
        
        int count = 0;
        boolean end = true; 
        boolean toCount = false;
        while (true) {
            end = true;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    end = false;
                    break;
                }
            }
            
            if (end) {
                break;
            }
            
            
            toCount = false;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    toCount = true;
                }
                else {
                    if (toCount) count++;
                    toCount = false;
                    continue;
                }
            }
            if (toCount) count++;
        }
        
        System.out.println(count);
    }
} Main
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Collections;
import java.awt.Point;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] s = br.readLine().split(" ");
        int[] h = new int[n];
        
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(s[i]);
        }
        
        int count = 0;
        boolean end = true; 
        boolean toCount = false;
        while (true) {
            end = true;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    end = false;
                    break;
                }
            }
            
            if (end) {
                break;
            }
            
            
            toCount = false;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    toCount = true;
                }
                else {
                    if (toCount) count++;
                    toCount = false;
                    continue;
                }
            }
            if (toCount) count++;
        }
        
        System.out.println(count);
    }
}

