
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int ans = 0;
        int count = 0;  //水やり完了済
        boolean watered = false;

        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
            if (h[i] == 0) {
                count++;
            }
        }

        while (count < h.length) {
            for (int i = 0; i < N; i++) {
                // 0でなければ減らす
                if (h[i] > 0) {
                    h[i]--;
                    if (h[i] == 0) {
                        count++;
                    }
                    watered = true;
                    continue;
                }

                // 0になってたら別の水やり操作が必要
                if (watered) {
                    ans++;
                    watered = false;
                }
            }

            if (watered) {
                ans++;
                watered = false;
            }
        }

        out.println(ans);
    }
} import java.util.*; util.* java import static java.lang.System.*; import static java.lang.System.*; import static java.lang.System.*; public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int ans = 0;
        int count = 0;  //水やり完了済
        boolean watered = false;

        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
            if (h[i] == 0) {
                count++;
            }
        }

        while (count < h.length) {
            for (int i = 0; i < N; i++) {
                // 0でなければ減らす
                if (h[i] > 0) {
                    h[i]--;
                    if (h[i] == 0) {
                        count++;
                    }
                    watered = true;
                    continue;
                }

                // 0になってたら別の水やり操作が必要
                if (watered) {
                    ans++;
                    watered = false;
                }
            }

            if (watered) {
                ans++;
                watered = false;
            }
        }

        out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int ans = 0;
        int count = 0;  //水やり完了済
        boolean watered = false;

        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
            if (h[i] == 0) {
                count++;
            }
        }

        while (count < h.length) {
            for (int i = 0; i < N; i++) {
                // 0でなければ減らす
                if (h[i] > 0) {
                    h[i]--;
                    if (h[i] == 0) {
                        count++;
                    }
                    watered = true;
                    continue;
                }

                // 0になってたら別の水やり操作が必要
                if (watered) {
                    ans++;
                    watered = false;
                }
            }

            if (watered) {
                ans++;
                watered = false;
            }
        }

        out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int ans = 0;
        int count = 0;  //水やり完了済
        boolean watered = false;

        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
            if (h[i] == 0) {
                count++;
            }
        }

        while (count < h.length) {
            for (int i = 0; i < N; i++) {
                // 0でなければ減らす
                if (h[i] > 0) {
                    h[i]--;
                    if (h[i] == 0) {
                        count++;
                    }
                    watered = true;
                    continue;
                }

                // 0になってたら別の水やり操作が必要
                if (watered) {
                    ans++;
                    watered = false;
                }
            }

            if (watered) {
                ans++;
                watered = false;
            }
        }

        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 ans = 0; ans 0 int count = 0; count 0 boolean watered = false; watered false int[] h = new int[N]; h new int[N] N for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
            if (h[i] == 0) {
                count++;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            h[i] = sc.nextInt();
            if (h[i] == 0) {
                count++;
            }
        } {
            h[i] = sc.nextInt();
            if (h[i] == 0) {
                count++;
            }
        } h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc if (h[i] == 0) {
                count++;
            } h[i] == 0 h[i] h i 0 {
                count++;
            } count++ count while (count < h.length) {
            for (int i = 0; i < N; i++) {
                // 0でなければ減らす
                if (h[i] > 0) {
                    h[i]--;
                    if (h[i] == 0) {
                        count++;
                    }
                    watered = true;
                    continue;
                }

                // 0になってたら別の水やり操作が必要
                if (watered) {
                    ans++;
                    watered = false;
                }
            }

            if (watered) {
                ans++;
                watered = false;
            }
        } count < h.length count h.length h h.length {
            for (int i = 0; i < N; i++) {
                // 0でなければ減らす
                if (h[i] > 0) {
                    h[i]--;
                    if (h[i] == 0) {
                        count++;
                    }
                    watered = true;
                    continue;
                }

                // 0になってたら別の水やり操作が必要
                if (watered) {
                    ans++;
                    watered = false;
                }
            }

            if (watered) {
                ans++;
                watered = false;
            }
        } for (int i = 0; i < N; i++) {
                // 0でなければ減らす
                if (h[i] > 0) {
                    h[i]--;
                    if (h[i] == 0) {
                        count++;
                    }
                    watered = true;
                    continue;
                }

                // 0になってたら別の水やり操作が必要
                if (watered) {
                    ans++;
                    watered = false;
                }
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                // 0でなければ減らす
                if (h[i] > 0) {
                    h[i]--;
                    if (h[i] == 0) {
                        count++;
                    }
                    watered = true;
                    continue;
                }

                // 0になってたら別の水やり操作が必要
                if (watered) {
                    ans++;
                    watered = false;
                }
            } {
                // 0でなければ減らす
                if (h[i] > 0) {
                    h[i]--;
                    if (h[i] == 0) {
                        count++;
                    }
                    watered = true;
                    continue;
                }

                // 0になってたら別の水やり操作が必要
                if (watered) {
                    ans++;
                    watered = false;
                }
            } if (h[i] > 0) {
                    h[i]--;
                    if (h[i] == 0) {
                        count++;
                    }
                    watered = true;
                    continue;
                } h[i] > 0 h[i] h i 0 {
                    h[i]--;
                    if (h[i] == 0) {
                        count++;
                    }
                    watered = true;
                    continue;
                } h[i]-- h[i] h i if (h[i] == 0) {
                        count++;
                    } h[i] == 0 h[i] h i 0 {
                        count++;
                    } count++ count watered = true watered true continue; if (watered) {
                    ans++;
                    watered = false;
                } watered {
                    ans++;
                    watered = false;
                } ans++ ans watered = false watered false if (watered) {
                ans++;
                watered = false;
            } watered {
                ans++;
                watered = false;
            } ans++ ans watered = false watered false out.println(ans) out.println out ans String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int ans = 0;
        int count = 0;  //水やり完了済
        boolean watered = false;

        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
            if (h[i] == 0) {
                count++;
            }
        }

        while (count < h.length) {
            for (int i = 0; i < N; i++) {
                // 0でなければ減らす
                if (h[i] > 0) {
                    h[i]--;
                    if (h[i] == 0) {
                        count++;
                    }
                    watered = true;
                    continue;
                }

                // 0になってたら別の水やり操作が必要
                if (watered) {
                    ans++;
                    watered = false;
                }
            }

            if (watered) {
                ans++;
                watered = false;
            }
        }

        out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int ans = 0;
        int count = 0;  //水やり完了済
        boolean watered = false;

        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
            if (h[i] == 0) {
                count++;
            }
        }

        while (count < h.length) {
            for (int i = 0; i < N; i++) {
                // 0でなければ減らす
                if (h[i] > 0) {
                    h[i]--;
                    if (h[i] == 0) {
                        count++;
                    }
                    watered = true;
                    continue;
                }

                // 0になってたら別の水やり操作が必要
                if (watered) {
                    ans++;
                    watered = false;
                }
            }

            if (watered) {
                ans++;
                watered = false;
            }
        }

        out.println(ans);
    }
} Main

import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int ans = 0;
        int count = 0;  //水やり完了済
        boolean watered = false;

        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
            if (h[i] == 0) {
                count++;
            }
        }

        while (count < h.length) {
            for (int i = 0; i < N; i++) {
                // 0でなければ減らす
                if (h[i] > 0) {
                    h[i]--;
                    if (h[i] == 0) {
                        count++;
                    }
                    watered = true;
                    continue;
                }

                // 0になってたら別の水やり操作が必要
                if (watered) {
                    ans++;
                    watered = false;
                }
            }

            if (watered) {
                ans++;
                watered = false;
            }
        }

        out.println(ans);
    }
}
