#include <bits/stdc++.h>
using namespace std;
const long long int N = 4e5 + 5;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  if (n == 1) return cout << 0, 0;
  pair<long long int, long long int> best[n][2];
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < 2; j++) best[i][j] = {-1, -1};
  }
  long long int curr = 1;
  long long int ind[2] = {0, 0};
  for (long long int i = 0; i < n; i) {
    long long int j = i;
    long long int curr = 0;
    long long int prev = a[i];
    while (1) {
      if (j == n) {
        long long int f = -1;
        if (curr >= 0) f = 1;
        for (long long int k = 0; k < 2; k++) {
          best[ind[k]][0].first = j - 1;
          best[ind[k]][0].second = f * a[j - 1] - f * a[ind[k]];
          best[ind[k]][1].first = j - 2;
          best[ind[k]][1].second = f * a[j - 2] - f * a[ind[k]];
        }
        ind[0] = j - 1;
        ind[1] = j;
        break;
      }
      if (curr == 0) {
        if (a[j] > prev)
          curr = 1;
        else if (a[j] < prev)
          curr = -1;
        prev = a[j];
        j++;
        continue;
      }
      if (curr == 1) {
        if (a[j] >= prev)
          prev = a[j];
        else {
          for (long long int k = 0; k < 2; k++) {
            best[ind[k]][0].first = j - 1;
            best[ind[k]][0].second = a[j - 1] - a[ind[k]];
            best[ind[k]][1].first = j - 2;
            best[ind[k]][1].second = a[j - 2] - a[ind[k]];
          }
          ind[0] = j - 1;
          ind[1] = j;
          break;
        }
      }
      if (curr == -1) {
        if (a[j] <= prev)
          prev = a[j];
        else {
          for (long long int k = 0; k < 2; k++) {
            best[ind[k]][0].first = j - 1;
            best[ind[k]][0].second = -a[j - 1] + a[ind[k]];
            best[ind[k]][1].first = j - 2;
            best[ind[k]][1].second = -a[j - 2] + a[ind[k]];
          }
          ind[0] = j - 1;
          ind[1] = j;
          break;
        }
      }
      j++;
    }
    if (j == n) break;
    i = j - 1;
  }
  long long int dp[n];
  for (long long int i = 0; i < n; i++) dp[i] = 0;
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < 2; j++) {
      long long int val = 0;
      if (i) val = dp[i - 1];
      long long int nxt = best[i][j].first;
      long long int add = best[i][j].second;
      if (nxt == -1) continue;
      dp[nxt] = max(dp[nxt], add + val);
      ans = max(ans, dp[nxt]);
    }
  }
  cout << ans;
}
