import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main
{
    private static class Range {
        int from;
        int to;

        Range(int from, int to)
        {
            this.from = from;
            this.to = to;
        }
    }

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

        int[] hs = new int[n];
        for (int i = 0; i < n; i++) {
            hs[i] = 0;
        }

        int count = 0;
        while (true) {
            List<Range> ranges = new ArrayList<>();
            Integer start = null;
            boolean goal = true;
            for (int i = 0; i < n; i++) {
                if (xs[i] != hs[i]) {
                    goal = false;

                    if (start == null) {
                        start = i;
                    }
                }
                else {
                    if (start != null) {
                        ranges.add(new Range(start, i));
                        start = null;
                    }
                }
            }
            if (goal) {
                System.out.println(count);
                return;
            }

            if (start != null) {
                ranges.add(new Range(start, n));
            }

            for (Range range : ranges) {
                for (int i = range.from; i < range.to; i++) {
                    hs[i] += 1;
                }
                count++;
            }
        }
    }
}
 import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main
{
    private static class Range {
        int from;
        int to;

        Range(int from, int to)
        {
            this.from = from;
            this.to = to;
        }
    }

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

        int[] hs = new int[n];
        for (int i = 0; i < n; i++) {
            hs[i] = 0;
        }

        int count = 0;
        while (true) {
            List<Range> ranges = new ArrayList<>();
            Integer start = null;
            boolean goal = true;
            for (int i = 0; i < n; i++) {
                if (xs[i] != hs[i]) {
                    goal = false;

                    if (start == null) {
                        start = i;
                    }
                }
                else {
                    if (start != null) {
                        ranges.add(new Range(start, i));
                        start = null;
                    }
                }
            }
            if (goal) {
                System.out.println(count);
                return;
            }

            if (start != null) {
                ranges.add(new Range(start, n));
            }

            for (Range range : ranges) {
                for (int i = range.from; i < range.to; i++) {
                    hs[i] += 1;
                }
                count++;
            }
        }
    }
} Main public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] xs = new int[n];
        for (int i = 0; i < n; i++) {
            xs[i] = scanner.nextInt();
        }

        int[] hs = new int[n];
        for (int i = 0; i < n; i++) {
            hs[i] = 0;
        }

        int count = 0;
        while (true) {
            List<Range> ranges = new ArrayList<>();
            Integer start = null;
            boolean goal = true;
            for (int i = 0; i < n; i++) {
                if (xs[i] != hs[i]) {
                    goal = false;

                    if (start == null) {
                        start = i;
                    }
                }
                else {
                    if (start != null) {
                        ranges.add(new Range(start, i));
                        start = null;
                    }
                }
            }
            if (goal) {
                System.out.println(count);
                return;
            }

            if (start != null) {
                ranges.add(new Range(start, n));
            }

            for (Range range : ranges) {
                for (int i = range.from; i < range.to; i++) {
                    hs[i] += 1;
                }
                count++;
            }
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] xs = new int[n];
        for (int i = 0; i < n; i++) {
            xs[i] = scanner.nextInt();
        }

        int[] hs = new int[n];
        for (int i = 0; i < n; i++) {
            hs[i] = 0;
        }

        int count = 0;
        while (true) {
            List<Range> ranges = new ArrayList<>();
            Integer start = null;
            boolean goal = true;
            for (int i = 0; i < n; i++) {
                if (xs[i] != hs[i]) {
                    goal = false;

                    if (start == null) {
                        start = i;
                    }
                }
                else {
                    if (start != null) {
                        ranges.add(new Range(start, i));
                        start = null;
                    }
                }
            }
            if (goal) {
                System.out.println(count);
                return;
            }

            if (start != null) {
                ranges.add(new Range(start, n));
            }

            for (Range range : ranges) {
                for (int i = range.from; i < range.to; i++) {
                    hs[i] += 1;
                }
                count++;
            }
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int[] xs = new int[n]; xs new int[n] n for (int i = 0; i < n; i++) {
            xs[i] = scanner.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            xs[i] = scanner.nextInt();
        } {
            xs[i] = scanner.nextInt();
        } xs[i] = scanner.nextInt() xs[i] xs i scanner.nextInt() scanner.nextInt scanner int[] hs = new int[n]; hs new int[n] n for (int i = 0; i < n; i++) {
            hs[i] = 0;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            hs[i] = 0;
        } {
            hs[i] = 0;
        } hs[i] = 0 hs[i] hs i 0 int count = 0; count 0 while (true) {
            List<Range> ranges = new ArrayList<>();
            Integer start = null;
            boolean goal = true;
            for (int i = 0; i < n; i++) {
                if (xs[i] != hs[i]) {
                    goal = false;

                    if (start == null) {
                        start = i;
                    }
                }
                else {
                    if (start != null) {
                        ranges.add(new Range(start, i));
                        start = null;
                    }
                }
            }
            if (goal) {
                System.out.println(count);
                return;
            }

            if (start != null) {
                ranges.add(new Range(start, n));
            }

            for (Range range : ranges) {
                for (int i = range.from; i < range.to; i++) {
                    hs[i] += 1;
                }
                count++;
            }
        } true {
            List<Range> ranges = new ArrayList<>();
            Integer start = null;
            boolean goal = true;
            for (int i = 0; i < n; i++) {
                if (xs[i] != hs[i]) {
                    goal = false;

                    if (start == null) {
                        start = i;
                    }
                }
                else {
                    if (start != null) {
                        ranges.add(new Range(start, i));
                        start = null;
                    }
                }
            }
            if (goal) {
                System.out.println(count);
                return;
            }

            if (start != null) {
                ranges.add(new Range(start, n));
            }

            for (Range range : ranges) {
                for (int i = range.from; i < range.to; i++) {
                    hs[i] += 1;
                }
                count++;
            }
        } List<Range> ranges = new ArrayList<>(); ranges new ArrayList<>() Integer start = null; start null boolean goal = true; goal true for (int i = 0; i < n; i++) {
                if (xs[i] != hs[i]) {
                    goal = false;

                    if (start == null) {
                        start = i;
                    }
                }
                else {
                    if (start != null) {
                        ranges.add(new Range(start, i));
                        start = null;
                    }
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if (xs[i] != hs[i]) {
                    goal = false;

                    if (start == null) {
                        start = i;
                    }
                }
                else {
                    if (start != null) {
                        ranges.add(new Range(start, i));
                        start = null;
                    }
                }
            } {
                if (xs[i] != hs[i]) {
                    goal = false;

                    if (start == null) {
                        start = i;
                    }
                }
                else {
                    if (start != null) {
                        ranges.add(new Range(start, i));
                        start = null;
                    }
                }
            } if (xs[i] != hs[i]) {
                    goal = false;

                    if (start == null) {
                        start = i;
                    }
                }
                else {
                    if (start != null) {
                        ranges.add(new Range(start, i));
                        start = null;
                    }
                } xs[i] != hs[i] xs[i] xs i hs[i] hs i {
                    goal = false;

                    if (start == null) {
                        start = i;
                    }
                } goal = false goal false if (start == null) {
                        start = i;
                    } start == null start null {
                        start = i;
                    } start = i start i {
                    if (start != null) {
                        ranges.add(new Range(start, i));
                        start = null;
                    }
                } if (start != null) {
                        ranges.add(new Range(start, i));
                        start = null;
                    } start != null start null {
                        ranges.add(new Range(start, i));
                        start = null;
                    } ranges.add(new Range(start, i)) ranges.add ranges new Range(start, i) start = null start null if (goal) {
                System.out.println(count);
                return;
            } goal {
                System.out.println(count);
                return;
            } System.out.println(count) System.out.println System.out System System.out count return; if (start != null) {
                ranges.add(new Range(start, n));
            } start != null start null {
                ranges.add(new Range(start, n));
            } ranges.add(new Range(start, n)) ranges.add ranges new Range(start, n) for (Range range : ranges) {
                for (int i = range.from; i < range.to; i++) {
                    hs[i] += 1;
                }
                count++;
            } Range range ranges {
                for (int i = range.from; i < range.to; i++) {
                    hs[i] += 1;
                }
                count++;
            } {
                for (int i = range.from; i < range.to; i++) {
                    hs[i] += 1;
                }
                count++;
            } for (int i = range.from; i < range.to; i++) {
                    hs[i] += 1;
                } int i = range.from; int i = range.from; i range.from range range.from i < range.to i range.to range range.to i++ i++ i {
                    hs[i] += 1;
                } {
                    hs[i] += 1;
                } hs[i] += 1 hs[i] hs i 1 count++ count String[] args args private static class Range {
        int from;
        int to;

        Range(int from, int to)
        {
            this.from = from;
            this.to = to;
        }
    } Range int from; from int to; to Range(int from, int to)
        {
            this.from = from;
            this.to = to;
        } Range {
            this.from = from;
            this.to = to;
        } this.from = from this.from this this.from from this.to = to this.to this this.to to int from from int to to public class Main
{
    private static class Range {
        int from;
        int to;

        Range(int from, int to)
        {
            this.from = from;
            this.to = to;
        }
    }

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

        int[] hs = new int[n];
        for (int i = 0; i < n; i++) {
            hs[i] = 0;
        }

        int count = 0;
        while (true) {
            List<Range> ranges = new ArrayList<>();
            Integer start = null;
            boolean goal = true;
            for (int i = 0; i < n; i++) {
                if (xs[i] != hs[i]) {
                    goal = false;

                    if (start == null) {
                        start = i;
                    }
                }
                else {
                    if (start != null) {
                        ranges.add(new Range(start, i));
                        start = null;
                    }
                }
            }
            if (goal) {
                System.out.println(count);
                return;
            }

            if (start != null) {
                ranges.add(new Range(start, n));
            }

            for (Range range : ranges) {
                for (int i = range.from; i < range.to; i++) {
                    hs[i] += 1;
                }
                count++;
            }
        }
    }
} public class Main
{
    private static class Range {
        int from;
        int to;

        Range(int from, int to)
        {
            this.from = from;
            this.to = to;
        }
    }

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

        int[] hs = new int[n];
        for (int i = 0; i < n; i++) {
            hs[i] = 0;
        }

        int count = 0;
        while (true) {
            List<Range> ranges = new ArrayList<>();
            Integer start = null;
            boolean goal = true;
            for (int i = 0; i < n; i++) {
                if (xs[i] != hs[i]) {
                    goal = false;

                    if (start == null) {
                        start = i;
                    }
                }
                else {
                    if (start != null) {
                        ranges.add(new Range(start, i));
                        start = null;
                    }
                }
            }
            if (goal) {
                System.out.println(count);
                return;
            }

            if (start != null) {
                ranges.add(new Range(start, n));
            }

            for (Range range : ranges) {
                for (int i = range.from; i < range.to; i++) {
                    hs[i] += 1;
                }
                count++;
            }
        }
    }
} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main
{
    private static class Range {
        int from;
        int to;

        Range(int from, int to)
        {
            this.from = from;
            this.to = to;
        }
    }

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

        int[] hs = new int[n];
        for (int i = 0; i < n; i++) {
            hs[i] = 0;
        }

        int count = 0;
        while (true) {
            List<Range> ranges = new ArrayList<>();
            Integer start = null;
            boolean goal = true;
            for (int i = 0; i < n; i++) {
                if (xs[i] != hs[i]) {
                    goal = false;

                    if (start == null) {
                        start = i;
                    }
                }
                else {
                    if (start != null) {
                        ranges.add(new Range(start, i));
                        start = null;
                    }
                }
            }
            if (goal) {
                System.out.println(count);
                return;
            }

            if (start != null) {
                ranges.add(new Range(start, n));
            }

            for (Range range : ranges) {
                for (int i = range.from; i < range.to; i++) {
                    hs[i] += 1;
                }
                count++;
            }
        }
    }
}

