// Original C++ solution (slower):
#include <bits/stdc++.h>

 

#define MAXN (1 << 18)

#define ll long long

 

int n, q, A, B;

int x[MAXN];

ll seg1[MAXN << 1], seg2[MAXN << 1];

 

ll query(ll *seg, int u, int l, int r, int ql, int qr){

	if(ql <= l && r <= qr) return seg[u];

	int m = l + r >> 1, ls = u << 1, rs = ls | 1;

	ll ret = LLONG_MAX;

	if(!(m < ql)) ret = std::min(ret, query(seg, ls, l, m, ql, qr));

	if(!(qr < m + 1)) ret = std::min(ret, query(seg, rs, m + 1, r, ql, qr));

	return ret;

}

 

void insert(ll *seg, int u, int l, int r, int pos, ll val){

	if(l == r){

		seg[u] = val;

		return;

	}

	int m = l + r >> 1, ls = u << 1, rs = ls | 1;

	if(pos <= m) insert(seg, ls, l, m, pos, val);

	else insert(seg, rs, m + 1, r, pos, val);

	seg[u] = std::min(seg[ls], seg[rs]);

}

 

int main(){

	scanf("%d%d%d%d", &n, &q, &A, &B);

	memset(seg1, 0x7f, sizeof seg1);

	memset(seg2, 0x7f, sizeof seg2);

	x[0] = B;

	insert(seg1, 1, 1, n, A, A);

	insert(seg2, 1, 1, n, A, -A);

	ll delta = 0;

	for(int i = 1; i <= q; ++ i){

		scanf("%d", x + i);

		

		ll tmp1 = query(seg1, 1, 1, n, x[i] + 1, n) - x[i];

		ll tmp2 = query(seg2, 1, 1, n, 1, x[i]) + x[i];

		tmp1 = std::min(tmp1, tmp2);

		

//		ll now = query(seg1, 1, 1, n, x[i - 1], x[i - 1]) - x[i - 1] + delta;

//		if(tmp1 < now){

			insert(seg1, 1, 1, n, x[i - 1], tmp1 + x[i - 1] - std::abs(x[i] - x[i - 1]));

			insert(seg2, 1, 1, n, x[i - 1], tmp1 - x[i - 1] - std::abs(x[i] - x[i - 1]));

//		}

		

		delta += std::abs(x[i] - x[i - 1]);

	}

	ll ans = LLONG_MAX;

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

		ans = std::min(ans, query(seg1, 1, 1, n, i, i) - i + delta);

	}

	printf("%lld\n", ans);

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using namespace std;

typedef long long LL;

const int mod = 1e9 + 7;

const int MAXN = 200050;

int n, q, A, lst;

LL tag, mn[MAXN<<2][2];

void build(int i, int l, int r) {

	if(l == r) {

		mn[i][0] = abs(l-A) - l;

		mn[i][1] = abs(l-A) + l;

		return;

	}

	int mid = (l + r) >> 1;

	build(i<<1, l, mid);

	build(i<<1|1, mid+1, r);

	mn[i][0] = min(mn[i<<1][0], mn[i<<1|1][0]);

	mn[i][1] = min(mn[i<<1][1], mn[i<<1|1][1]);

}

LL qry(int i, int l, int r, int x, int y, int o) {

	if(x <= l && r <= y) return mn[i][o];

	int mid = (l + r) >> 1; LL re = 1ll<<60;

	if(x <= mid) re = min(re, qry(i<<1, l, mid, x, y, o));

	if(y > mid) re = min(re, qry(i<<1|1, mid+1, r, x, y, o));

	return re;

}

void upd(int i, int l, int r, int x, LL val) {

	if(l == r) {

		if(val < mn[i][0]+l+tag) {

			mn[i][0] = val-tag-l;

			mn[i][1] = val-tag+l;

		}

		return;

	}

	int mid = (l + r) >> 1;

	if(x <= mid) upd(i<<1, l, mid, x, val);

	else upd(i<<1|1, mid+1, r, x, val);

	mn[i][0] = min(mn[i<<1][0], mn[i<<1|1][0]);

	mn[i][1] = min(mn[i<<1][1], mn[i<<1|1][1]);

}

LL ans;

void dfs(int i, int l, int r) {

	if(l == r) {

		ans = min(ans, mn[i][0]+l+tag);

		return;

	}

	int mid = (l + r) >> 1;

	dfs(i<<1, l, mid);

	dfs(i<<1|1, mid+1, r);

}

int main () {

	scanf("%d%d%d%d", &n, &q, &lst, &A);

	build(1, 1, n);

	for(int i = 1, x; i <= q; lst = x, ++i) {

		scanf("%d", &x);

		LL val = qry(1, 1, n, 1, x, 0) + tag + x;

		if(x < n) val = min(val, qry(1, 1, n, x+1, n, 1) + tag - x);

		tag += abs(x-lst);

		upd(1, 1, n, lst, val);

	}

	ans = 1ll<<60;

	dfs(1, 1, n);

	printf("%lld\n", ans);

}

// Fastest known solution for this problem: