#include <bits/stdc++.h>
inline int read() {
  int ret;
  scanf("%d", &ret);
  return ret;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
struct SGT {
  struct Seg {
    int l, r;
    long long mx;
  } seg[1223456 * 4];
  void buildtree(int l, int r, int now = 1) {
    seg[now].l = l;
    seg[now].r = r;
    seg[now].mx = -0X5FFFFFFFFFFFFFFFll;
    if (l == r) return;
    int m = (l + r) >> 1;
    buildtree(l, m, now * 2);
    buildtree(m + 1, r, now * 2 + 1);
  }
  long long query(int l, int r, int now = 1) {
    if (l <= seg[now].l && seg[now].r <= r) return seg[now].mx;
    int m = (seg[now].l + seg[now].r) >> 1;
    long long ret = -0X5FFFFFFFFFFFFFFFll;
    if (l <= m) ret = max(ret, query(l, r, now * 2));
    if (r > m) ret = max(ret, query(l, r, now * 2 + 1));
    return ret;
  }
  void update(int x, long long val, int now = 1) {
    if (seg[now].l == seg[now].r) {
      seg[now].mx = max(seg[now].mx, val);
      return;
    }
    int m = (seg[now].l + seg[now].r) >> 1;
    if (x <= m)
      update(x, val, now * 2);
    else
      update(x, val, now * 2 + 1);
    seg[now].mx = max(seg[now * 2].mx, seg[now * 2 + 1].mx);
  }
} sp, sm;
long long a[1223456], b[1223456];
int n;
long long dp[1223456];
int id(long long x) { return lower_bound(b + 1, b + n + 1, x) - b; }
int Main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= int(n); i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1);
  long long ans = 0;
  sm.buildtree(1, n);
  sp.buildtree(1, n);
  for (int i = 1; i <= n; i++) {
    int r = id(a[i]);
    long long tmp = sm.query(1, r);
    if (tmp != -0X5FFFFFFFFFFFFFFFll) dp[i] = max(dp[i], tmp + a[i]);
    tmp = sp.query(r, n);
    if (tmp != -0X5FFFFFFFFFFFFFFFll) dp[i] = max(dp[i], tmp - a[i]);
    sm.update(r, ans - a[i]);
    sp.update(r, ans + a[i]);
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
  return 0;
}
int main() { return Main(); }
