import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{//try{
	auto tokens = split(my_readln());
	auto N = to!ulong(tokens[0]);

	long[] h;
	foreach (token; split(my_readln()))
	{
		h ~= to!long(token);
	}

	ulong[] costs;
	costs.length = N;
	fill(costs, ulong.max);
	costs[0] = 0;
	foreach (i; 0..N-2)
	{
		costs[i+1] = min(costs[i+1], costs[i] + abs(h[i] - h[i+1]));
		costs[i+2] = min(costs[i+2], costs[i] + abs(h[i] - h[i+2]));
	}
	costs[N-1] = min(costs[N-1], costs[N-2] + abs(h[N-2] - h[N-1]));

	writeln(costs[N-1]);
	stdout.flush();
	/*}catch (Throwable e)
	{
	writeln(e.toString());
	}
	readln();*/
}