#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] - a[i - 1] <= 0) {
      continue;
    }
    ans += a[i] - a[i - 1];
  }
  cout << ans << endl;
}
