unittest
{
	assert( [ "3 3", "1 7 11" ].parse.expand.solve == 2 );
	assert( [ "3 81", "33 105 57" ].parse.expand.solve == 24 );
	assert( [ "1 1", "1000000000" ].parse.expand.solve == 999999999 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto np = input.front.split.to!( long[] );
	input.popFront;
	auto xs = input.front.split.to!( long[] );
	return tuple( np[ 0 ], np[ 1 ], xs );
}

auto solve( long n, long p, long[] xs )
{
	// 出発地点から一番近い都市までの距離を出す
	xs.sort();
	
	if( p < xs[ 0 ] ) return xs[ 0 ] - p;
	if( xs[ $ - 1 ] < p ) return p - xs[ $ - 1 ];
	
	for( auto i = 1; i < xs.length; i++ )
	{
		if( p < xs[ i ] )
		{
			auto r = xs[ i ] - p;
			auto l = p - xs[ i - 1 ];
			return min( r, l );
		}
	}
	
	assert( false );
}
