#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0, s = a[0];
  for (int i = 0; i < n; i++) {
    if (s < a[i]) {
      s = a[i];
      ans += a[i] - s;
    } else
      ans += s - a[i];
  }
  cout << ans << endl;
}
