

import java.util.Scanner;

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

        int res = 0;
        while(true) {
            int max = 0;
            for(int i = 0; i < N; i++) {
                max = Math.max(max, arr[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j < N) {
                if(arr[j] == 0) j++;
                else {
                    res++;
                    while(j < N && arr[j] > 0) {
                        arr[j]--;
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

        int res = 0;
        while(true) {
            int max = 0;
            for(int i = 0; i < N; i++) {
                max = Math.max(max, arr[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j < N) {
                if(arr[j] == 0) j++;
                else {
                    res++;
                    while(j < N && arr[j] > 0) {
                        arr[j]--;
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

        int res = 0;
        while(true) {
            int max = 0;
            for(int i = 0; i < N; i++) {
                max = Math.max(max, arr[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j < N) {
                if(arr[j] == 0) j++;
                else {
                    res++;
                    while(j < N && arr[j] > 0) {
                        arr[j]--;
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

        int res = 0;
        while(true) {
            int max = 0;
            for(int i = 0; i < N; i++) {
                max = Math.max(max, arr[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j < N) {
                if(arr[j] == 0) j++;
                else {
                    res++;
                    while(j < N && arr[j] > 0) {
                        arr[j]--;
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] arr = new int[N]; arr new int[N] N for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            arr[i] = sc.nextInt();
        } {
            arr[i] = sc.nextInt();
        } arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc int res = 0; res 0 while(true) {
            int max = 0;
            for(int i = 0; i < N; i++) {
                max = Math.max(max, arr[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j < N) {
                if(arr[j] == 0) j++;
                else {
                    res++;
                    while(j < N && arr[j] > 0) {
                        arr[j]--;
                        j++;
                    }
                }
            }
        } true {
            int max = 0;
            for(int i = 0; i < N; i++) {
                max = Math.max(max, arr[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j < N) {
                if(arr[j] == 0) j++;
                else {
                    res++;
                    while(j < N && arr[j] > 0) {
                        arr[j]--;
                        j++;
                    }
                }
            }
        } int max = 0; max 0 for(int i = 0; i < N; i++) {
                max = Math.max(max, arr[i]);
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                max = Math.max(max, arr[i]);
            } {
                max = Math.max(max, arr[i]);
            } max = Math.max(max, arr[i]) max Math.max(max, arr[i]) Math.max Math max arr[i] arr i if(max == 0) break; max == 0 max 0 break; int j = 0; j 0 while(j < N) {
                if(arr[j] == 0) j++;
                else {
                    res++;
                    while(j < N && arr[j] > 0) {
                        arr[j]--;
                        j++;
                    }
                }
            } j < N j N {
                if(arr[j] == 0) j++;
                else {
                    res++;
                    while(j < N && arr[j] > 0) {
                        arr[j]--;
                        j++;
                    }
                }
            } if(arr[j] == 0) j++;
                else {
                    res++;
                    while(j < N && arr[j] > 0) {
                        arr[j]--;
                        j++;
                    }
                } arr[j] == 0 arr[j] arr j 0 j++ j {
                    res++;
                    while(j < N && arr[j] > 0) {
                        arr[j]--;
                        j++;
                    }
                } res++ res while(j < N && arr[j] > 0) {
                        arr[j]--;
                        j++;
                    } j < N && arr[j] > 0 j < N j N arr[j] > 0 arr[j] arr j 0 {
                        arr[j]--;
                        j++;
                    } arr[j]-- arr[j] arr j j++ j System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

        int res = 0;
        while(true) {
            int max = 0;
            for(int i = 0; i < N; i++) {
                max = Math.max(max, arr[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j < N) {
                if(arr[j] == 0) j++;
                else {
                    res++;
                    while(j < N && arr[j] > 0) {
                        arr[j]--;
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

        int res = 0;
        while(true) {
            int max = 0;
            for(int i = 0; i < N; i++) {
                max = Math.max(max, arr[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j < N) {
                if(arr[j] == 0) j++;
                else {
                    res++;
                    while(j < N && arr[j] > 0) {
                        arr[j]--;
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    }
} Main


import java.util.Scanner;

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

        int res = 0;
        while(true) {
            int max = 0;
            for(int i = 0; i < N; i++) {
                max = Math.max(max, arr[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j < N) {
                if(arr[j] == 0) j++;
                else {
                    res++;
                    while(j < N && arr[j] > 0) {
                        arr[j]--;
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    }
}
