#111. Copy

内存限制:256 MiB 时间限制:1000 ms 标准输入输出
题目类型:传统 评测方式:文本比较
上传者: syzoj

题目描述

YHZ led ACM teams for many years. As you know, he hates others to copy his homework. Yesterday he met a difficult problem.

He got an array A with n elements. All are non-negative. He wants to reduce each element to zero. The only operation is choosing an interval, and reduce each element in it by 1 .

He wants to minimize the number of operations, could you help him? Please be reminded that at any time, the elements cannot be negative.

输入格式

There is only one test case.

The first line contains a integer n . The second line contains n integers, indicating the elements in the array.

输出格式

Output only one line. The minimum number of operations.

样例

Sample Input

5
2 3 4 1 2

Sample Output

5

数据范围与提示

1 \leq n \leq 10^5 , 1 \leq A_i \leq 10^4

In the sample input, one possible way is [1, 5][1, 3][2, 3][3, 3][5, 5]. It can be proved that there are no ways which cost less than 5 operations.