#include using namespace std; typedef long long LL; const int N = 1000010; int a[N]; LL ans; int n; //贪心法 int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) if (a[i] > a[i - 1]) ans += a[i] - a[i - 1]; cout << ans; return 0; }