#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e6 + 7;
long long n, minl, maxl, a[maxN], dp[maxN];
int main() {
  scanf("%I64d", &n);
  for (long long i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  for (long long i = 1; i <= n; i++) {
    while (i + minl < n && a[i + minl] > a[i + minl + 1]) minl++;
    while (i + maxl < n && a[i + maxl] < a[i + maxl + 1]) maxl++;
    dp[i + minl] = max(dp[i + minl], dp[i - 1] + a[i] - a[i + minl]);
    if (minl > 1)
      dp[i + minl - 1] =
          max(dp[i + minl - 1], dp[i - 1] + a[i] - a[i + minl - 1]);
    dp[i + maxl] = max(dp[i + maxl], dp[i - 1] + a[i + maxl] - a[i]);
    if (maxl > 1)
      dp[i + maxl - 1] =
          max(dp[i + maxl - 1], dp[i - 1] + a[i + maxl - 1] - a[i]);
    minl = max(0LL, minl - 1);
    maxl = max(0LL, maxl - 1);
  }
  printf("%I64d\n", dp[n]);
}
