#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<bool> need(n, false);
  for (int i = 1; i < n - 1; ++i) {
    if (a[i] >= a[i - 1] && a[i] >= a[i + 1]) {
      need[i - 1] = true;
      need[i] = true;
      need[i + 1] = true;
    } else if (a[i] <= a[i - 1] && a[i] <= a[i + 1]) {
      need[i - 1] = true;
      need[i] = true;
      need[i + 1] = true;
    }
  }
  need[0] = need[n - 1] = true;
  vector<long long> b;
  for (int i = 0; i < n; ++i) {
    if (need[i]) {
      b.push_back(a[i]);
    }
  }
  vector<long long> dp((int)b.size(), 0);
  for (int i = 1; i < (int)b.size(); ++i) {
    dp[i] = abs(b[i] - b[0]);
    int kek = max(0, i - 5);
    for (int j = i; j > kek; --j) {
      dp[i] = max(dp[i], dp[j - 1] + abs(b[i] - b[j]));
    }
  }
  cout << dp[(int)b.size() - 1] << endl;
  return 0;
}
