#include <bits/stdc++.h>
using namespace std;
const long long Sz = 1e6 + 5;
long long a[Sz];
long long f[Sz];
long long mn[Sz];
long long mx[Sz];
vector<long long> zip;
void RAR() {
  zip.push_back(-2e9);
  sort(zip.begin(), zip.end());
  zip.erase(unique(zip.begin(), zip.end()), zip.end());
}
long long UNRAR(long long x) {
  return lower_bound(zip.begin(), zip.end(), x) - zip.begin();
}
void UpMin(long long x, long long v) {
  for (long long i = x; i < Sz; i += i & (-i)) mn[i] = max(mn[i], v);
}
void UpMax(long long x, long long v) {
  for (long long i = x; i > 0; i -= i & (-i)) mx[i] = max(mx[i], v);
}
long long GetMin(long long x) {
  long long ans = -1e15;
  for (long long i = x; i > 0; i -= i & (-i)) ans = max(ans, mn[i]);
  return ans;
}
long long GetMax(long long x) {
  long long ans = -1e15;
  for (long long i = x; i < Sz; i += i & (-i)) ans = max(ans, mx[i]);
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fill(mn, mn + Sz, -2e9);
  fill(mx, mx + Sz, -2e9);
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    zip.push_back(a[i]);
  }
  RAR();
  for (long long i = 1; i <= n; i++) {
    long long p = UNRAR(a[i]);
    UpMin(p, f[i - 1] - a[i]);
    UpMax(p, f[i - 1] + a[i]);
    f[i] = max(GetMin(p) + a[i], GetMax(p) - a[i]);
  }
  cout << f[n] << "\n";
  return 0;
}
