#include<iostream>
#include<cstring>
using namespace std;
const int N = 100010;
long long w[N], f[2][N];
int main()
{
int n;
cin >> n;
for(int i = 1; i <= n; i++) cin >> w[i];
memset(f, -0x3f, sizeof(f));
for(int i = 0; i <= n; i++) f[0][i] = 0;
f[1][1] = f[0][0] - w[1];
for(int i = 1; i <= n; i++)
{
f[0][i] = max(f[0][i - 1], f[1][i - 1] + w[i]);
if(i != 1)
f[1][i] = max(f[0][i - 2] - w[i], f[1][i - 1]);
}
// for(int i = 1; i <= n; i++) cout << f[0][i] << " " << f[1][i] << endl;
cout << f[0][n] << endl;
return 0;
}