#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> height(N);
  for (int i = 0; i < N; i++) {
    cin >> height[i];
  }
  vector<int> step(N);
  step[0] = 0;
  for (int i = 1; i < N; i++) {
    int diff = height[i] - height[i - 1] - step[i - 1];
    if (diff >= 0) {
      step[i] = 0;
    } else {
      step[i] = -diff;
    }
  }
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += step[i];
  }
  cout << sum << endl;
}
