import java.util.Scanner;

public class Main {

    private static int findPositiveIndex(int[] h) {
        for(int i = 0; i < h.length; i++) {
            if (h[i] > 0) return i;
        }
        return -1;
    }

    private static int solve(int[] h) {
        int cur = findPositiveIndex(h);
        int count = 0;

        while (cur >= 0) {
            for(int i = cur; i < h.length; i++) {
                if(h[i] > 0) {
                    h[i] -= 1;
                } else {
                    break;
                }
            }
            count += 1;
            cur = findPositiveIndex(h);
        }

        return count;
    }

    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 ans = solve(h);
        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    private static int findPositiveIndex(int[] h) {
        for(int i = 0; i < h.length; i++) {
            if (h[i] > 0) return i;
        }
        return -1;
    }

    private static int solve(int[] h) {
        int cur = findPositiveIndex(h);
        int count = 0;

        while (cur >= 0) {
            for(int i = cur; i < h.length; i++) {
                if(h[i] > 0) {
                    h[i] -= 1;
                } else {
                    break;
                }
            }
            count += 1;
            cur = findPositiveIndex(h);
        }

        return count;
    }

    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 ans = solve(h);
        System.out.println(ans);
    }
} Main private static int findPositiveIndex(int[] h) {
        for(int i = 0; i < h.length; i++) {
            if (h[i] > 0) return i;
        }
        return -1;
    } findPositiveIndex {
        for(int i = 0; i < h.length; i++) {
            if (h[i] > 0) return i;
        }
        return -1;
    } for(int i = 0; i < h.length; i++) {
            if (h[i] > 0) return i;
        } 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 i;
        } {
            if (h[i] > 0) return i;
        } if (h[i] > 0) return i; h[i] > 0 h[i] h i 0 return i; i return -1; -1 1 int[] h h private static int solve(int[] h) {
        int cur = findPositiveIndex(h);
        int count = 0;

        while (cur >= 0) {
            for(int i = cur; i < h.length; i++) {
                if(h[i] > 0) {
                    h[i] -= 1;
                } else {
                    break;
                }
            }
            count += 1;
            cur = findPositiveIndex(h);
        }

        return count;
    } solve {
        int cur = findPositiveIndex(h);
        int count = 0;

        while (cur >= 0) {
            for(int i = cur; i < h.length; i++) {
                if(h[i] > 0) {
                    h[i] -= 1;
                } else {
                    break;
                }
            }
            count += 1;
            cur = findPositiveIndex(h);
        }

        return count;
    } int cur = findPositiveIndex(h); cur findPositiveIndex(h) findPositiveIndex h int count = 0; count 0 while (cur >= 0) {
            for(int i = cur; i < h.length; i++) {
                if(h[i] > 0) {
                    h[i] -= 1;
                } else {
                    break;
                }
            }
            count += 1;
            cur = findPositiveIndex(h);
        } cur >= 0 cur 0 {
            for(int i = cur; i < h.length; i++) {
                if(h[i] > 0) {
                    h[i] -= 1;
                } else {
                    break;
                }
            }
            count += 1;
            cur = findPositiveIndex(h);
        } for(int i = cur; i < h.length; i++) {
                if(h[i] > 0) {
                    h[i] -= 1;
                } else {
                    break;
                }
            } int i = cur; int i = cur; i cur i < h.length i h.length h h.length i++ i++ i {
                if(h[i] > 0) {
                    h[i] -= 1;
                } else {
                    break;
                }
            } {
                if(h[i] > 0) {
                    h[i] -= 1;
                } else {
                    break;
                }
            } if(h[i] > 0) {
                    h[i] -= 1;
                } else {
                    break;
                } h[i] > 0 h[i] h i 0 {
                    h[i] -= 1;
                } h[i] -= 1 h[i] h i 1 {
                    break;
                } break; count += 1 count 1 cur = findPositiveIndex(h) cur findPositiveIndex(h) findPositiveIndex h return count; count int[] h h 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 ans = solve(h);
        System.out.println(ans);
    } 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 ans = solve(h);
        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 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 ans = solve(h); ans solve(h) solve h System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

    private static int findPositiveIndex(int[] h) {
        for(int i = 0; i < h.length; i++) {
            if (h[i] > 0) return i;
        }
        return -1;
    }

    private static int solve(int[] h) {
        int cur = findPositiveIndex(h);
        int count = 0;

        while (cur >= 0) {
            for(int i = cur; i < h.length; i++) {
                if(h[i] > 0) {
                    h[i] -= 1;
                } else {
                    break;
                }
            }
            count += 1;
            cur = findPositiveIndex(h);
        }

        return count;
    }

    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 ans = solve(h);
        System.out.println(ans);
    }
} public class Main {

    private static int findPositiveIndex(int[] h) {
        for(int i = 0; i < h.length; i++) {
            if (h[i] > 0) return i;
        }
        return -1;
    }

    private static int solve(int[] h) {
        int cur = findPositiveIndex(h);
        int count = 0;

        while (cur >= 0) {
            for(int i = cur; i < h.length; i++) {
                if(h[i] > 0) {
                    h[i] -= 1;
                } else {
                    break;
                }
            }
            count += 1;
            cur = findPositiveIndex(h);
        }

        return count;
    }

    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 ans = solve(h);
        System.out.println(ans);
    }
} Main
import java.util.Scanner;

public class Main {

    private static int findPositiveIndex(int[] h) {
        for(int i = 0; i < h.length; i++) {
            if (h[i] > 0) return i;
        }
        return -1;
    }

    private static int solve(int[] h) {
        int cur = findPositiveIndex(h);
        int count = 0;

        while (cur >= 0) {
            for(int i = cur; i < h.length; i++) {
                if(h[i] > 0) {
                    h[i] -= 1;
                } else {
                    break;
                }
            }
            count += 1;
            cur = findPositiveIndex(h);
        }

        return count;
    }

    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 ans = solve(h);
        System.out.println(ans);
    }
}
