#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, step = 0, k, P, S;
  cin >> N;
  for (k = 1; k <= N; k++) {
    if (k == 1) {
      cin >> P;
    }
    cin >> S;
    if (P <= S) {
      step += (S - P);
      P = S;
    } else {
      P = S;
    }
  }
  cout << step << endl;
  return 0;
}
