#include<iostream>
#include<cstdio>
#include<string>
#include<cstdlib>


using namespace std;

int arr[10001];

int main(){
    int n;
    cin>>n;
    for(int i = 0;i < n;++i){
        cin>>arr[i];
    }
    int index = 0,sum = 0;
    while(index < n){
        int a = abs(arr[index + 1] - arr[index]);
        int b = abs(arr[index + 2] - arr[index]);
        if(b <= a){
            index += 2;
            sum += abs(arr[index + 2] - arr[index]);
        }
        else{
            index += 1;
            sum += abs(arr[index + 1] - arr[index]);
        }
    }
    printf("%d\n",sum);
    return 0;
}
