// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define mp make_pair

#define pb push_back

#define st first

#define nd second

#define lb lower_bound

#define ub upper_bound



typedef long long ll;

typedef long double ld;

typedef pair<int,int> pi;

typedef pair<ll,ll> pll;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef vector<pi> vpi;

typedef vector<pll> vpll;



const ll oo=1e18;

const int MOD=1000000007;

const int INF=1000000000;

const ld EPS=0.000000001;



int dp[100005],h[100005],n,k=2;



signed main() {

    ios_base::sync_with_stdio(NULL);

    cin.tie(NULL);

    cout.tie(NULL);

    memset(dp,0x3f3f,sizeof dp);

    dp[1]=0;

    h[0]=0;

    cin>>n;

    for(int i=1;i<=n;++i) cin>>h[i];

    for(int i=2;i<=n;++i) {

        for(int j=1;j<=min(k,i);++j) {

            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));

        }

    }

    cout<<dp[n];

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.392856049533974x):
/*

██╗  ██╗ █████╗ ██████╗ ███████╗███████╗███╗   ███╗        ██╗  ██╗██╗  ██╗ █████╗ ██╗     ███████╗██████╗

██║ ██╔╝██╔══██╗██╔══██╗██╔════╝██╔════╝████╗ ████║        ██║ ██╔╝██║  ██║██╔══██╗██║     ██╔════╝██╔══██╗

█████╔╝ ███████║██████╔╝█████╗  █████╗  ██╔████╔██║        █████╔╝ ███████║███████║██║     █████╗  ██║  ██║

██╔═██╗ ██╔══██║██╔══██╗██╔══╝  ██╔══╝  ██║╚██╔╝██║        ██╔═██╗ ██╔══██║██╔══██║██║     ██╔══╝  ██║  ██║

██║  ██╗██║  ██║██║  ██║███████╗███████╗██║ ╚═╝ ██║███████╗██║  ██╗██║  ██║██║  ██║███████╗███████╗██████╔╝

╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═════╝

Believe in yourself ,( try and try and then try ), You can do it  

*/

#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

#include<unordered_map>

#define endl "\n"

#define Ceil(x,y) ((x+y-1)/y)

#define clr(arr, x) memset(arr, x, sizeof arr)

#define all(v) v.begin(),v.end()

#define allr(s) s.rbegin(),s.rend()

#define rt(s) return cout<<s,0

#define watch(x) cout<<(#x)<<" = "<<x<<endl

#define sz(s)	(int)(s.size())

#define OO 0x3f3f3f3f3f3f3f3fLL

const int oo = 0x3f3f3f3f, mod = 1e9 + 7;

using namespace std;

typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;

//x = xDegrees*3.14159265 / 180;

//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);

//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));

int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };

int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };

void K_K(){

	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}

ll gcd(ll a, ll b) {

	return b == 0 ? abs(a) : gcd(b, a % b);

}

ll lcm(ll a, ll b) {

	return a / gcd(a, b) * b;

}

int n;

vector<int>arr;

map < pair<int, int>, int > dp;

int sol(int idx, int cur){

	if (idx >= n){

		if (cur == arr[n - 1])

			return 0;

		return oo;

	}

	if (dp.find({ idx, cur }) != dp.end())

		return dp[{idx, cur}];

	int ch1 = sol(idx + 1, arr[idx]) + abs(cur - arr[idx]);

	int ch2 = sol(idx + 2, arr[idx]) + abs(cur - arr[idx]);

	return dp[{idx, cur}] = min(ch1, ch2);

}

int main(){

	K_K();

	cin >> n;

	arr.resize(n);

	for (auto &it : arr)

		cin >> it;

	cout << sol(0, arr[0]);

}