#include <bits/stdc++.h>
using namespace std;
int n;
long long a[2000005], dp[2000006];
bool flag[2000005];
long long rec(int x) {
  if (x > n - 2) return 0;
  long long &rt = dp[x];
  if (flag[x]) return rt;
  flag[x] = true;
  if ((a[x] < a[x - 1] && a[x] < a[x + 1]) ||
      (a[x] > a[x - 1] && a[x] > a[x + 1])) {
    rt = abs(a[x] - a[x - 1]);
    rt += rec(x + 1);
    rt = min(rt, abs(a[x] - a[x + 1]) + rec(x + 2));
  } else
    rt = rec(x + 1);
  return rt;
}
int main() {
  scanf("%d", &n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    if (i) sum += abs(a[i] - a[i - 1]);
  }
  sum -= rec(1);
  printf("%lld\n", sum);
}
