#include <bits/stdc++.h>
using namespace std;
const unsigned int M = 1000000007;
int main() {
  int a;
  cin >> a;
  vector<int> b(a);
  int ans = 0;
  for (int i = 0; i < a; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < a - 1; i++) {
    if (b[i] > b[i + 1]) {
      ans += b[i] - b[i + 1];
    }
  }
  cout << ans + 1 << endl;
  return 0;
}
