#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n;
  vector<int> A;
  int max = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    A.push_back(x);
  }
  for (int i = 1; i < n; i++) ans += A[i] - A[i - 1];
  cout << ans;
}
