#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int last = 0;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    if (last) {
      ans += max(0, t - last);
    }
    last = t;
  }
  cout << ans << endl;
  return 0;
}
