#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
int a[200001], b[200001];
int inc = 0;
int d = 0;
void fun(int i, int n) {
  if (a[i] == (b[i] + inc - d))
    return;
  else if ((b[i] + inc - d) < a[i]) {
    int diff = a[i] - b[i] - inc + d;
    inc += diff;
    ans += diff;
  } else {
    int diff = b[i] + inc - d - a[i];
    d += diff;
    ans += diff;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = 0;
  }
  for (int i = 0; i < n; i++) fun(i, n);
  cout << ans;
  return 0;
}
