#include <iostream>
#include <cmath>

using namespace std;

int l[10000];

int main (){
    int n = 0;
    int x = 0;
    int m = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> l[i];
    }
    l[n] = 1000000;
    while(m != n-1){
        if(m < n-2){
            if(abs(l[m]-l[m+1]) < abs(l[m]-l[m+2])){
                m+=1;
                x+= abs(l[m]-l[m+1]);
            }
            else{
                m+=2;
                x+=abs(l[m]-l[m+2]);
            }
        }
        else{
            m +=1;
            x+=abs(l[m]-l[m+2]);
        }
    }
    cout<<x;
    return 0;
}
