#include <bits/stdc++.h>
using namespace std;
int ft[200001];
int n;
void upd(int pos, int val) {
  while (pos <= n) {
    ft[pos] += val;
    pos += pos & (-pos);
  }
}
int query(int pos) {
  int ret = 0;
  while (pos) {
    ret += ft[pos];
    pos -= pos & (-pos);
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  vector<int> v;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    int cur = query(i);
    int diff = x - cur;
    upd(i, diff);
    ans += (long long)abs(diff);
  }
  printf("%lld\n", ans);
  return 0;
}
