#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  std::vector<long long> a(n);
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long res = 0;
  long long cc = a[0];
  for (long long int i = 0; i < n; i++) {
    if (a[i] == cc) {
      continue;
    }
    if (a[i] < cc) {
      res += cc - a[i];
    } else {
      res += a[i] - cc;
      cc = a[i];
    }
  }
  cout << res;
}
