#include <bits/stdc++.h>
using namespace std;
long long dp[1000010];
long long arr[1000010];
int N;
inline void ReadInput(void) {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%I64d", &arr[i]);
}
inline void solve(void) {
  int pos = 1;
  int foo = 2;
  for (int i = 2; i <= N; i++) {
    if (arr[i] != arr[foo]) foo = i;
    dp[i] = max(dp[pos - 1] + abs(arr[pos] - arr[i]),
                dp[pos] + abs(arr[i] - arr[pos + 1]));
    if (arr[i] > arr[foo - 1] and arr[i] > arr[i + 1]) pos = i;
    if (arr[i] < arr[foo - 1] and arr[i] < arr[i + 1]) pos = i;
  }
  cout << dp[N];
}
inline void Refresh(void) {}
int main() {
  ios_base::sync_with_stdio(false);
  ReadInput();
  solve();
  return 0;
}
