#include <bits/stdc++.h>
using namespace std;
long long get_ans(vector<pair<long long, int> >& v) {
  if (v.size() < 2) return 0;
  vector<pair<long long, long long> > dp(v.size(), make_pair((0ll), (0ll)));
  int n = v.size();
  long long prevt = 0;
  for (int i = 1; i < n; ++i) {
    if (!v[i].second) continue;
    dp[i].first =
        max(dp[prevt].first + max(v[i].first - v[prevt + 1].first, 0ll),
            dp[prevt].second + max(v[i].first - v[prevt].first, 0ll));
    dp[i].second =
        max(dp[prevt].first + max(v[i - 1].first - v[prevt + 1].first, 0ll),
            dp[prevt].second + max(v[i - 1].first - v[prevt].first, 0ll));
    prevt = i;
  }
  return max(dp[prevt].first, dp[prevt].second);
}
void solve() {
  int n;
  scanf("%d", &n);
  vector<long long> v(n);
  for (int i = 0; i < n; ++i) scanf("%I64d", &v[i]);
  vector<pair<long long, int> > tmp;
  long long ans = 0;
  tmp.push_back(make_pair((v[0]), (1)));
  int napr = 1;
  for (int i = 1; i < n; ++i) {
    if (v[i] == v[i - 1]) {
      tmp.back().second = 1;
      ans += get_ans(tmp);
      tmp.clear();
      tmp.push_back(make_pair((v[i]), (1)));
      napr = 1;
      continue;
    }
    if (v[i] > v[i - 1]) {
      if (napr)
        tmp.push_back(make_pair((tmp.back().first + v[i] - v[i - 1]), (0)));
      else {
        tmp.back().second = 1;
        tmp.push_back(make_pair((tmp.back().first + v[i] - v[i - 1]), (0)));
        napr = 1 - napr;
      }
    } else {
      if (!napr)
        tmp.push_back(make_pair((tmp.back().first + v[i - 1] - v[i]), (0)));
      else {
        tmp.back().second = 1;
        tmp.push_back(make_pair((tmp.back().first + v[i - 1] - v[i]), (0)));
        napr = 1 - napr;
      }
    }
  }
  tmp.back().second = 1;
  ans += get_ans(tmp);
  printf("%I64d", ans);
}
int main() {
  std::ios_base::sync_with_stdio(false);
  solve();
  return 0;
}
