#include <iostream>
using namespace std;
const int N = 1e5 + 10;
const int INF = 1e9 + 10;
int w[N];
// 没股票
int f[N];
// 有股票
int g[N];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> w[i];
}
g[0] = -INF;
for (int i = 1; i <= n; ++i) {
f[i] = max(f[i - 1], g[i - 1] + w[i]);
g[i] = max(g[i - 1], f[i - 1] - w[i]);
}
cout << f[n] << endl;
return 0;
}