using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
namespace Codeforces
{
internal class Template
{
private long[] queries = new long[200200];
private long qq;
private Dictionary<Tuple<long, long, long>, long> dp;
private void Solve()
{
//var n = cin.NextLong();
//var x = new long[n];
//var y = new long[n];
//var min = long.MaxValue;
//var max = long.MinValue;
//for (var i = 0; i < n; i++)
//{
// x[i] = cin.NextLong();
// y[i] = cin.NextLong();
// min = Math.Min(min, Math.Min(x[i], y[i]));
// max = Math.Max(max, Math.Max(x[i], y[i]));
// if (x[i] > y[i])
// {
// var temp = x[i];
// x[i] = y[i];
// y[i] = temp;
// }
//}
//var ma
var n = cin.NextLong();
qq = cin.NextLong();
var a = cin.NextLong();
var b = cin.NextLong();
for (var i = 0; i < qq; i++)
{
queries[i] = cin.NextLong();
}
dp = new Dictionary<Tuple<long, long, long>, long>();
var res = Calc(0, Math.Min(a, b), Math.Max(a, b));
Console.WriteLine(res);
}
private long Calc(long q, long a, long b)
{
if (q == qq)
{
return 0;
}
var key = Tuple.Create(q, Math.Min(a, b), Math.Max(a, b));
if (dp.ContainsKey(key))
{
return dp[key];
}
var best = long.MaxValue;
if (queries[q] <= a)
{
best = Calc(q + 1, queries[q], b) + Math.Abs(a - queries[q]);
}
else if (queries[q] >= b)
{
best = Calc(q + 1, a, queries[q]) + Math.Abs(b - queries[q]);
}
else
{
best = Math.Min(Calc(q + 1, queries[q], b) + Math.Abs(a - queries[q]),
Calc(q + 1, a, queries[q]) + Math.Abs(b - queries[q]));
}
dp[key] = best;
return best;
}
private static readonly Scanner cin = new Scanner();
private static void Main()
{
#if DEBUG
var inputText = File.ReadAllText(@"..\..\input.txt");
var testCases = inputText.Split(new[] { "input" }, StringSplitOptions.RemoveEmptyEntries);
var consoleOut = Console.Out;
for (var i = 0; i < testCases.Length; i++)
{
var parts = testCases[i].Split(new[] { "output" }, StringSplitOptions.RemoveEmptyEntries);
Console.SetIn(new StringReader(parts[0].Trim()));
var stringWriter = new StringWriter();
Console.SetOut(stringWriter);
var sw = Stopwatch.StartNew();
new Template().Solve();
sw.Stop();
var output = stringWriter.ToString();
Console.SetOut(consoleOut);
var color = ConsoleColor.Green;
var status = "Passed";
if (parts[1].Trim() != output.Trim())
{
color = ConsoleColor.Red;
status = "Failed";
}
Console.ForegroundColor = color;
Console.WriteLine("Test {0} {1} in {2}ms", i + 1, status, sw.ElapsedMilliseconds);
}
Console.ReadLine();
Console.ReadKey();
#else
new Template().Solve();
Console.ReadLine();
#endif
}
}
internal class Scanner
{
private string[] s = new string[0];
private int i;
private readonly char[] cs = { ' ' };
public string NextString()
{
if (i < s.Length) return s[i++];
var line = Console.ReadLine() ?? string.Empty;
s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 1;
return s.First();
}
public double NextDouble()
{
return double.Parse(NextString());
}
public int NextInt()
{
return int.Parse(NextString());
}
public long NextLong()
{
return long.Parse(NextString());
}
}
}