#include <bits/stdc++.h>
using namespace std;
int n, x, y, z;
long long ans, lastadd, curadd;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  if (n == 1) {
    cout << "0\n";
    return 0;
  }
  cin >> x >> y;
  lastadd = abs(y - x);
  ans = lastadd;
  for (int i = 2; i < n; i++) {
    cin >> z;
    curadd = abs(z - y);
    if (z >= y ^ y >= x) curadd -= min(curadd, lastadd);
    ans += curadd;
    x = y;
    y = z;
    lastadd = curadd;
  }
  cout << ans << "\n";
  return 0;
}
