#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, sum, data[1000];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> data[i];
    sum += data[i + 1] - data[i];
  }
  cout << sum << endl;
  return 0;
}
