// Arup Guha
// 5/16/2018
// Solution to 2015 April USACO Silver Question: Trapped in the Haybales

import java.util.*;
import java.io.*;

public class trapped {

	public static void main(String[] args) throws Exception {

		BufferedReader stdin = new BufferedReader(new FileReader("trapped.in"));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		int n = Integer.parseInt(tok.nextToken());
		int bessiePos = Integer.parseInt(tok.nextToken());

		// Read in the hay bales.
		pair[] bales = new pair[n];
		for (int i=0; i<n; i++) {
			tok = new StringTokenizer(stdin.readLine());
			int size = Integer.parseInt(tok.nextToken());
			int pos = Integer.parseInt(tok.nextToken());
			bales[i] = new pair(size, pos);
		}

		// Solve and write out the result.
		FileWriter fout = new FileWriter(new File("trapped.out"));
		fout.write(solve(bales, bessiePos, n)+"\n");
		fout.close();
	}

	public static int solve(pair[] bales, int bessiePos, int n) {

		Arrays.sort(bales);

		// Find Bessie's relative position.
		int index = 0;
		while (index < n && bessiePos > bales[index].pos) index++;

		// Can't do it in thies case.
		if (index == 0 || index == n) return -1;

		// Set up initial pointers.
		int low = index-1, high = index, res = Integer.MAX_VALUE;
		int tmpLeft = low-1, tmpRight = high+1;

		// Sweep in both directions.
		while (low >= 0 && high < n) {

			// We are stuck, answer is 0!
			int maxD = bales[high].pos - bales[low].pos;
			if (bales[high].size >= maxD && bales[low].size >= maxD) return 0;

			// One thing we could do is fortify high, update our result and increment high.
			else if (bales[high].size < maxD && bales[low].size >= maxD) {
				res = Math.min(res, maxD-bales[high].size);
				high++;
			}

			// Or here we could fortify low...
			else if (bales[high].size >= maxD && bales[low].size < maxD) {
				res = Math.min(res, maxD-bales[low].size);
				low--;
			}

			// Here both walls can come down...
			else {

				// See where our stopping point is going left.
				int tmpStop = Integer.MAX_VALUE;
				while (tmpLeft >= 0 && bales[tmpLeft].size < (bales[high].pos-bales[tmpLeft].pos)) tmpLeft--;

				// And right.
				while (tmpRight < n && bales[tmpRight].size < (bales[tmpRight].pos-bales[low].pos)) tmpRight++;

				// Can't trap bessie if we let her get this far.
				if (tmpLeft < 0 && tmpRight == n) {
					if (res == Integer.MAX_VALUE) return -1;
					return res;
				}

				// Here we fortify to the right.
				if (tmpLeft >= 0)
					res = Math.min(res, bales[high].pos-bales[tmpLeft].pos-bales[high].size);

				// Here we fortify to the left.
				if (tmpRight < n)
					res = Math.min(res, bales[tmpRight].pos-bales[low].pos-bales[low].size);

				// We can update both now.
				low--;
				high++;
			}
		}

		// Return accordingly when we get here.
		if (res == Integer.MAX_VALUE) return -1;
		return res;
	}
}

class pair implements Comparable<pair> {

	public int size;
	public int pos;

	public pair(int s, int p) {
		size = s;
		pos = p;
	}

	public int compareTo(pair other) {
		return this.pos - other.pos;
	}

	public String toString() {
		return size+":"+pos;
	}
}