#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
  return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
  os << '[';
  for (unsigned long long i = 0; i < a.size(); i++)
    os << a[i] << (i < a.size() - 1 ? ", " : "");
  os << ']';
  return os;
}
long long n;
long long a[N];
long long dp[N][2][2];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = (long long)1; i <= (long long)n; i++) {
    cin >> a[i];
  }
  memset(dp, -127, sizeof(dp));
  dp[0][1][1] = 0;
  dp[0][0][0] = dp[0][0][1] = dp[0][1][0] = -1e18;
  for (long long i = (long long)1; i <= (long long)n; i++) {
    dp[i][1][0] = max(dp[i][1][0], dp[i - 1][1][1] - a[i]);
    dp[i][1][0] = max(dp[i][1][0], dp[i - 1][1][0]);
    dp[i][0][1] = max(dp[i][0][1], dp[i - 1][1][1] + a[i]);
    dp[i][0][1] = max(dp[i][0][1], dp[i - 1][0][1]);
    dp[i][1][1] = max(dp[i][1][1], dp[i - 1][0][1] - a[i]);
    dp[i][1][1] = max(dp[i][1][1], dp[i - 1][1][0] + a[i]);
    dp[i][1][1] = max(dp[i][1][1], dp[i - 1][1][1]);
  }
  cout << dp[n][1][1] << '\n';
}
