import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    auto n = lread();
    auto h = aryread();
    // writeln(h);
    // writeln(h.maxElement);
    long cnt;
    while (true)
    {
        if (h.maxElement == 0)
        {
            break;
        }
        long i;
        while (i < n)
        {
            if (h[i] == 0)
            {
                i += 1;
            }
            else
            {
                cnt += 1;
                while ((i < n) && (h[i] > 0))
                {
                    h[i] -= 1;
                    i += 1;
                }
            }

        }
    }
    writeln(cnt);

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}
