import java.util.*;

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

        boolean needsWatering = true;
        int numWaters = 0;
        while (needsWatering) {
            needsWatering = false;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    h[i]--;
                    needsWatering = true;
                    if (i == n - 1 || h[i + 1] == 0) {
                        numWaters++;
                    }
                }
            }
        }

        System.out.println(numWaters);

    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = in.nextInt();
        }

        boolean needsWatering = true;
        int numWaters = 0;
        while (needsWatering) {
            needsWatering = false;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    h[i]--;
                    needsWatering = true;
                    if (i == n - 1 || h[i + 1] == 0) {
                        numWaters++;
                    }
                }
            }
        }

        System.out.println(numWaters);

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

        boolean needsWatering = true;
        int numWaters = 0;
        while (needsWatering) {
            needsWatering = false;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    h[i]--;
                    needsWatering = true;
                    if (i == n - 1 || h[i + 1] == 0) {
                        numWaters++;
                    }
                }
            }
        }

        System.out.println(numWaters);

    } main {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = in.nextInt();
        }

        boolean needsWatering = true;
        int numWaters = 0;
        while (needsWatering) {
            needsWatering = false;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    h[i]--;
                    needsWatering = true;
                    if (i == n - 1 || h[i + 1] == 0) {
                        numWaters++;
                    }
                }
            }
        }

        System.out.println(numWaters);

    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int[] h = new int[n]; h new int[n] n for (int i = 0; i < n; i++) {
            h[i] = in.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            h[i] = in.nextInt();
        } {
            h[i] = in.nextInt();
        } h[i] = in.nextInt() h[i] h i in.nextInt() in.nextInt in boolean needsWatering = true; needsWatering true int numWaters = 0; numWaters 0 while (needsWatering) {
            needsWatering = false;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    h[i]--;
                    needsWatering = true;
                    if (i == n - 1 || h[i + 1] == 0) {
                        numWaters++;
                    }
                }
            }
        } needsWatering {
            needsWatering = false;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    h[i]--;
                    needsWatering = true;
                    if (i == n - 1 || h[i + 1] == 0) {
                        numWaters++;
                    }
                }
            }
        } needsWatering = false needsWatering false for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    h[i]--;
                    needsWatering = true;
                    if (i == n - 1 || h[i + 1] == 0) {
                        numWaters++;
                    }
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if (h[i] != 0) {
                    h[i]--;
                    needsWatering = true;
                    if (i == n - 1 || h[i + 1] == 0) {
                        numWaters++;
                    }
                }
            } {
                if (h[i] != 0) {
                    h[i]--;
                    needsWatering = true;
                    if (i == n - 1 || h[i + 1] == 0) {
                        numWaters++;
                    }
                }
            } if (h[i] != 0) {
                    h[i]--;
                    needsWatering = true;
                    if (i == n - 1 || h[i + 1] == 0) {
                        numWaters++;
                    }
                } h[i] != 0 h[i] h i 0 {
                    h[i]--;
                    needsWatering = true;
                    if (i == n - 1 || h[i + 1] == 0) {
                        numWaters++;
                    }
                } h[i]-- h[i] h i needsWatering = true needsWatering true if (i == n - 1 || h[i + 1] == 0) {
                        numWaters++;
                    } i == n - 1 || h[i + 1] == 0 i == n - 1 i n - 1 n 1 h[i + 1] == 0 h[i + 1] h i + 1 i 1 0 {
                        numWaters++;
                    } numWaters++ numWaters System.out.println(numWaters) System.out.println System.out System System.out numWaters String[] args args public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = in.nextInt();
        }

        boolean needsWatering = true;
        int numWaters = 0;
        while (needsWatering) {
            needsWatering = false;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    h[i]--;
                    needsWatering = true;
                    if (i == n - 1 || h[i + 1] == 0) {
                        numWaters++;
                    }
                }
            }
        }

        System.out.println(numWaters);

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

        boolean needsWatering = true;
        int numWaters = 0;
        while (needsWatering) {
            needsWatering = false;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    h[i]--;
                    needsWatering = true;
                    if (i == n - 1 || h[i + 1] == 0) {
                        numWaters++;
                    }
                }
            }
        }

        System.out.println(numWaters);

    }
} Main
import java.util.*;

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

        boolean needsWatering = true;
        int numWaters = 0;
        while (needsWatering) {
            needsWatering = false;
            for (int i = 0; i < n; i++) {
                if (h[i] != 0) {
                    h[i]--;
                    needsWatering = true;
                    if (i == n - 1 || h[i + 1] == 0) {
                        numWaters++;
                    }
                }
            }
        }

        System.out.println(numWaters);

    }
}
