Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary order.

Vasya wants to pick such checkpoints and the order of visiting them that the total distance travelled is minimized. He asks you to calculate this minimum possible value.


-----Input-----

The first line of the input contains two integers n and a (1 ≤ n ≤ 100 000,  - 1 000 000 ≤ a ≤ 1 000 000) — the number of checkpoints and Vasya's starting position respectively.

The second line contains n integers x_1, x_2, ..., x_{n} ( - 1 000 000 ≤ x_{i} ≤ 1 000 000) — coordinates of the checkpoints.


-----Output-----

Print one integer — the minimum distance Vasya has to travel in order to visit at least n - 1 checkpoint.


-----Examples-----
Input
3 10
1 7 12

Output
7

Input
2 0
11 -10

Output
10

Input
5 0
0 0 1000 0 0

Output
0



-----Note-----

In the first sample Vasya has to visit at least two checkpoints. The optimal way to achieve this is the walk to the third checkpoints (distance is 12 - 10 = 2) and then proceed to the second one (distance is 12 - 7 = 5). The total distance is equal to 2 + 5 = 7.

In the second sample it's enough to visit only one checkpoint so Vasya should just walk to the point  - 10.

Difficulty: interview

Starter code:

Solutions:
from math import *
n, a = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
if n == 1:
    print(0)
    
else:
    if a > A[-1]:
        print(abs(a - A[1]))
    elif a < A[0]:
        print(abs(a - A[-2]))
    else:
        per1 = abs(A[0] - A[-2])
        per2 = abs(A[1] - A[-1])
        ans1 = abs(A[0] - a) + per1
        ans2 = per1 + abs(A[-2] - a)
        ans3 = per2 + abs(a - A[-1])
        ans4 = per2 + abs(a - A[1])
        print(min(ans1, ans2, ans3, ans4))

#!/usr/bin/env python3.5
import sys

def read_data():
    n, x0 = list(map(int, next(sys.stdin).split()))
    checkpoints = list(map(int, next(sys.stdin).split()))
    return x0, checkpoints


def solve(x0, checkpoints):
    n = len(checkpoints)
    checkpoints.sort()
    if n == 1:
        return 0
    case0 = abs(x0 - checkpoints[1]) + abs(checkpoints[n-1] - checkpoints[1])
    case1 = abs(x0 - checkpoints[n-2]) + abs(checkpoints[0] - checkpoints[n-2])
    case2 = abs(x0 - checkpoints[0]) + abs(checkpoints[n-2] - checkpoints[0])
    case3 = abs(x0 - checkpoints[n-1]) + abs(checkpoints[1] - checkpoints[n-1])
    return min(case0, case1, case2, case3)


def __starting_point():
    x0, checkpoints = read_data()
    length = solve(x0, checkpoints)
    print(length)

__starting_point()

def calc_dist(coords, a):
    if len(coords) == 0:
        return 0
    
    if a > coords[-1]:
        return a - coords[0]
    if a < coords[0]:
        return coords[-1] - a
    
    return coords[-1] - coords[0] + min(a - coords[0], coords[-1] - a)


n, a = list(map(int, input().split()))

coords = list(map(int, input().split()))

coords.sort()

#~ print(coords[:-1], coords[1:])

print(min(calc_dist(coords[:-1], a), calc_dist(coords[1:], a)))


n, a = [int(i) for i in input().split()]

points = [int(i) for i in input().split()]

right = None
right2 = None
left = None
left2 = None

for point in points:
    if right is None:
        right = point

    else:
        if point > right:
            right2 = right
            right = point
        elif right2 is None or point > right2:
            right2 = point

    if left is None:
        left = point
    else:
        if point < left:
            left2 = left
            left = point
        elif left2 is None or point < left2:
            left2 = point


if n == 1:
    print(0)
elif a >= right:
    print(a-left2)
elif a <= left:
    print(right2-a)

else:
    x1 = abs(a-left)+abs(right2-left)
    x2 = abs(a-left2)+abs(right-left2)
    x3 = abs(right-a)+abs(right-left2)
    x4 = abs(right2-a)+abs(right2-left)
    print(min((x1,x2,x3,x4)))
    


n, a = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
if n == 1:
    print(0)
elif n == 2:
    print(min(abs(c[0] - a), abs(c[1] - a)))
else:
    if abs(c[0] - a) < abs(c[n - 2] - a):
        ans = abs(c[0] - a) + abs(c[0] - c[n - 2])
    else:
        ans = abs(c[n - 2] - a) + abs(c[0] - c[n - 2])
    if abs(c[1] - a) < abs(c[n - 1] - a):
        ans = min(ans, abs(c[1] - a) + abs(c[1] - c[n - 1]))
    else:
        ans = min(ans, abs(c[n - 1] - a) + abs(c[n - 1] - c[1]))
    print(ans)

n, a = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
s.sort()
t = len(s)-1
for i in range(n):
	if s[i] >a:
		t = i-1
		break
if n == 1:
	print(0)
elif t == -1:
	print(abs(s[-2]-a))
elif t == n-1:
	print(abs(a-s[1]))
elif t == 0:
	print(min(abs(s[-1]-a), abs(s[-2]-s[0]+a-s[0]), abs(s[-2]-s[0]+s[-2]-a)))
elif t == n-2:
	print(min(abs(a-s[0]), abs(s[-1]-s[1]+s[-1]-a), abs(s[-1]-s[1]+a-s[1])))
else:
	ans = min(abs(s[-1]-s[1]+a-s[1]),abs(s[-1]-s[1]+s[-1]-a), abs(s[-2]-s[0]+a-s[0]), abs(s[-2]-s[0]+s[-2]-a))
	print(ans)



n, a = list(map(int, input().split()))
x = list(map(int, input().split()))
def visit(a,b,c):
    if a<=b:
        return c-a
    if a>=c:
        return a-b
    return c-b + min(c-a, a-b)
x.sort()
if n <= 1:
    print(0)
elif a <= x[0]:
    print(x[-2]-a)
elif a >= x[-1]:
    print(a-x[1])
else:
    #~ ans = 10**7
    print(min(visit(a, x[0], x[-2]), visit(a,x[1],x[-1])))
    


# You lost the game.
n,a = list(map(int, input().split()))
L = list(map(int, input().split()))
L.sort()
if n == 1:
    print(0)
elif a >= L[n-1]:
    print(a-L[1])
elif a <= L[0]:
    print(L[n-2]-a)
else:
    gauche = min(abs(a - L[0]),abs(L[n-2] - a)) + L[n-2] - L[0]
    droite = min(abs(a - L[1]),abs(L[n-1] - a)) + L[n-1] - L[1]
    if gauche < droite:
        print(gauche)
    else:
        print(droite)


# -*- coding: utf-8 -*-
"""
Created on Wed Aug 24 12:53:13 2016

@author: Felicia
"""

inp1 = input()
inp11 = inp1.split(' ')
n = int(inp11[0])
a = int(inp11[1])

inp2 = input()
inp21 = inp2.split(' ')
x0 = []
for i in inp21:
    j=int(i)
    x0.append(j)

x = sorted(x0)

def f(x):
    if x>0:
        return x
    else:
        return 0
if n>1:
    len1 = 2*f(a-x[0])+f(x[n-2]-a)
    len2 = 2*f(x[n-2]-a)+f(a-x[0])
    len3 = 2*f(a-x[1])+f(x[n-1]-a)
    len4 = 2*f(x[n-1]-a)+f(a-x[1])
    
    print(min(len1,len2,len3,len4))
else:
    print(0)

n, a = list(map(int, input().split()))
x = list(map(int, input().split()))

x.sort()
res = 2**30

def solve(a, i, j):
    if a >= x[j]:
        return a - x[i]
    elif a <= x[i]:
        return x[j] - a
    else:
        sumLeft = (a - x[i]) * 2 + x[j] - a
        sumRight = (x[j] - a) * 2 + a - x[i]
        return min(sumLeft, sumRight)

if n <= 1:
    res = 0

elif n == 2:
    for value in x:
        res = min(res, abs(value - a))
else:
    if a <= x[0]:
        res = x[len(x) - 2] - a;
    elif a >= x[len(x) - 1]:
        res = a - x[1]
    else:
        leftValue = solve(a, 1, len(x) - 1)
        rightValue = solve(a, 0, len(x) - 2)
        res = min(leftValue, rightValue)

print(res)



n,a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.sort()
if(len(b) == 1):
    print(0)
elif(len(b) == 2):
    print(min(abs(a - b[0]), abs(a - b[1])))
elif(a < b[0]):
    print(b[-2] - a)
elif(a > b[-1]):
    print(a - b[1])
elif(a == b[0]):
    print(b[-2] - a)
elif(a == b[-1]):
    print(a - b[1])
elif(len(b) == 3):
    if(a < b[1]):
        print(min(a - b[0] - b[0] + b[1], b[1]-a + b[1]-a + a-b[0], b[2] - a))
    elif(a > b[1]):
        print(min(a - b[0], a - b[1] + a - b[1] + b[2] - a, b[2] - a + b[2] - a + a - b[1]))
    else:
        print(min(a - b[0], b[2] - a))
elif(a < b[1]):
    print(min(a - b[0] + a - b[0] + b[-2] - a, b[-2] - a + b[-2] - a + a - b[0], b[-1] - a))
elif(a > b[-2]):
    print(min(a - b[0], b[-1] - a + b[-1] - a + a - b[1], a - b[1] + a - b[1] + b[-1] - a))
else:
    print(min(a - b[1] + a - b[1] + b[-1] - a, b[-1] - a + b[-1] - a + a - b[1],a - b[0] + a - b[0] + b[-2] - a, b[-2] - a + b[-2] - a + a - b[0]))


n,a=list(map(int,input().split()))
ip=list(map(int,input().split()))
try:
    if a not in ip:
        ip.append(a)
        n+=1
    ip=sorted(ip)
    k=ip.index(a)
    l1=0
    l2=0
    for i in range(k):
        l1+=ip[i+1]-ip[i]
    for i in range(k,n-1):
        l2+=ip[i+1]-ip[i]
    n1=ip[1]-ip[0]
    n2=ip[-1]-ip[-2]
    if l1==0:
        print(l2-n2)
    elif l2==0:
        print(l1-n1)
    else:
        print(min(l1-n1+2*l2, 2*l1-2*n1+l2, l2-n2+2*l1, 2*l2-2*n2+l1))
except:
    print(0)


n, a = list(map(int, input().split()))
line = list(map(int, input().split()))
line.sort()
if len(line) == 1:
    print(0)
else:    
    r1 = abs(line[-1] - line[1])
    otvet1 = min(abs(a - line[1]), abs(a - line[-1])) + r1
    r2 = abs(line[-2] - line[0])
    otvet2 = min(abs(a - line[-2]), abs(a - line[0])) + r2
    print(min(otvet1, otvet2))

#!/usr/bin/env python3

from sys import stdin


def main():
    n, a = stdin_get_ints_from_line()
    x = stdin_get_ints_list_from_line()
    x.sort()

    if n == 1:
        print(0)
        return

    #print(get_result(a, x[1], x[-1]), get_result(a, x[1], x[-1]))

    print(min(get_result(a, x[1], x[-1]), get_result(a, x[0], x[-2])))


def get_result(a, left, right):
    #print(a, left, right)
    if left < a < right:
        if abs(a-left) < abs(a-right): # go left first
            return (abs(a-left) * 2) + abs(a-right)
        else:
            return abs(a-left) + (abs(a-right) * 2)

    if a <= left:
        return abs(a-right)

    if a >= right:
        return abs(a-left)


def stdin_get_ints_from_line():
    return (int(x) for x in stdin.readline().strip().split(' '))


def stdin_get_ints_list_from_line():
    return list(int(x) for x in stdin.readline().strip().split(' '))


def stdin_get_string_from_line():
    return stdin.readline().strip()


def __starting_point():
    main()

__starting_point()

n,p = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort()
if n==1:
    print(0)
elif n==2:
    print(min(abs(a[0]-p),abs(a[1]-p)))

else:
    a1 = min(abs(a[0]-p),abs(a[-2]-p)) + abs(a[0]-a[-2])
    a2 = min(abs(a[1]-p),abs(a[-1]-p)) + abs(a[1]-a[-1])
    print(min(a1,a2))





n, a = list(map(int, input().split()))
x = list(map(int, input().split()))

x.sort()
res = 2**30

def solve(a, i, j):
    if a >= x[j]:
        return a - x[i]
    elif a <= x[i]:
        return x[j] - a
    else:
        sumLeft = (a - x[i]) * 2 + x[j] - a
        sumRight = (x[j] - a) * 2 + a - x[i]
        return min(sumLeft, sumRight)

if n <= 1:
    res = 0

elif n == 2:
    for value in x:
        res = min(res, abs(value - a))
else:
    if a <= x[0]:
        res = x[len(x) - 2] - a;
    elif a >= x[len(x) - 1]:
        res = a - x[1]
    else:
        leftValue = solve(a, 1, len(x) - 1)
        rightValue = solve(a, 0, len(x) - 2)
        res = min(leftValue, rightValue)

print(res)



n,x=[int(i) for i in input().strip().split()]
a=[int(i) for i in input().strip().split() if int(i)!=x]
if len(a)<=1:
  ans=0
else:
  a=sorted([x]+a)
  ind=a.index(x)
  if ind==0:
    ans=a[-2]-a[0]
  elif ind==len(a)-1:
    ans=a[-1]-a[1]
  else:
    ans=min((a[ind]+a[-2]-2*a[0]), (2*a[-2]-a[ind]-a[0]), (a[ind]+a[-1]-2*a[1]), (2*a[-1]-a[ind]-a[1]))
print(ans)

N, A = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
if N == 1:
    print(0)
    return
elif N == 2:
    print(min(abs(X[0] - A), abs(X[1] - A)))
    return
ans = int(1e18)
ans = min(ans, abs(X[N-2] - X[0]) + min(abs(A - X[0]), abs(A - X[N-2])))
ans = min(ans, abs(X[N-1] - X[1]) + min(abs(A - X[1]), abs(A - X[N-1])))
print(ans)


n, a = list(map(int, input().split(' ')))
x = list(map(int, input().split(' ')))

MAX, MIN = 1000000, -1000000

r1, r2, l1, l2 = MIN-1, MIN-1, MAX+1, MAX+1

for xi in x:
    if xi <= l1:
        l2 = l1
        l1 = xi
    elif xi < l2:
        l2 = xi
        
    if xi >= r1:
        r2 = r1
        r1 = xi
    elif xi > r2:
        r2 = xi

if n == 1:
    print(0)
else:        
    print((min(
        r1 - l2 + abs(a - r1),
        r1 - l2 + abs(a - l2),
        r2 - l1 + abs(a - r2),
        r2 - l1 + abs(a - l1))))


n,d = map(int,input().split())
a = list(map(int,input().strip().split()))

#print(n)
#print(a)
a.sort()
#print(a)

ans =0
if n==1:
    ans=0
elif n<=2:
    ans = min(abs(a[0]-d),abs(a[n-1]-d))     
else:
   # print("en")
    ans =a[n-2]-a[0] + min(abs(a[0]-d),abs(a[n-2]-d))
    #print(ans)    
    ans = min(ans,a[n-1]-a[1] + min(abs(a[1]-d),abs(a[n-1]-d)))
   # print(ans)
print(ans)

from math import *

[n, a] = [int(x) for x in input().split()]

if n == 1:
    print(0)
    return

points = [int(x) for x in input().split()]
points.sort()

dis1 = abs(points[n-2] - points[0])
dis2 = abs(points[n-1] - points[1])

to0 = abs(a - points[0])
to1 = abs(a - points[1])
ton = abs(a - points[n-1])
ton2 = abs(a - points[n-2])

print(min(to0 + dis1, to1 + dis2, ton + dis2, ton2 + dis1))

def solve():
    n, a = list(map(int, input().split()))
    x = list(map(int, input().split()))
    x.append(a)
    x.sort()
    bi = 0
    for i in range(n + 1):
        if x[i] == a:
            bi = i
            break
    ans = float('inf')
    for s in range(2):
        l = 0
        r = 0
        ok = x[s] == a
        for i in range(s + 1, s + n):
            ok = ok or x[i] == a
            if i <= bi:
                l += x[i] - x[i - 1]
            else:
                r += x[i] - x[i - 1]
        if ok:
            ans = min(ans, min(l, r) * 2 + max(l, r))
    print(ans)


def main():
    solve()


def __starting_point():
    main()

__starting_point()

n, a = list(map(int, input().split()))

l = input().split()
l = [int(i) for i in l]

if(n == 1):
    print(0)
elif(n == 2):
    if(abs(a-l[0]) < abs(a-l[1])):
        print(abs(a-l[0]))
    else:
        print(abs(a-l[1]))
else:
    ma = max(l)
    mi = min(l)
    l.remove(ma)
    max2 = max(l)
    l.append(ma)
    l.remove(mi)
    min2 = min(l)
    l.append(mi)

    if(a > ma):
        print(a-min2)
    elif(a < mi):
        print(max2-a)
    else:
        ans=list()
        ans.append(abs(max2 - a) + max2 - mi)
        ans.append(abs(a - mi) + max2 - mi)
        ans.append(ma - min2 + abs(ma - a))
        ans.append(ma - min2 + abs(a - min2))
        while(min(ans) < 0):
            ans.remove(min(ans))
        print(min(ans))


n, a = map(int, input().split())
N = sorted(list(map(int, input().split())))
dist = 0
 
if n == 1:
    dist = 0
   
elif n == 2:
    dist = min(abs(N[0] - a), abs(N[1] - a))
   
elif a <= N[0]:
    dist = abs(N[-2] - a)
   
elif a >= N[-1]:
    dist = abs(a - N[1])

elif a >= N[-2]:
    dist = min(abs(a - N[0]), 2 * abs(a - N[-1]) + abs(a - N[1]), abs(a - N[-1]) + 2 * abs(a - N[1]))

elif a <= N[1]:
    dist = min(abs(a - N[-1]), 2 * abs(a - N[0]) + abs(a - N[-2]), abs(a - N[0]) + 2 * abs(a - N[-2]))
   
else:
    dist = min(2 * abs(N[0] - a) + abs(N[-2] - a), 2 * abs(N[1] - a) + abs(N[-1] - a), 2 * abs(N[-1] - a) + abs(N[1] - a), 2 * abs(N[-2] - a) + abs(N[0] - a))


print(dist)