import java.io.*;
import java.util.*;

public class fitness_af_wrong1 implements Runnable {
	public static void main(String[] args) {
		new Thread(new fitness_af_wrong1()).start();
	}

	Scanner in;
	PrintWriter out;

	public void run() {
		try {
			in = new Scanner(new File("fitness.in"));
			out = new PrintWriter("fitness.out");
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(-1);
		}

	}

	boolean between(double l, double x, double r) {
		return l <= x && x <= r || r <= x && x <= l;
	}

	void myAssert(boolean e, String msg) {
		if (!e) {
			throw new Error(msg);
		}
	}

	void solve() throws IOException {
		int n = in.nextInt();
		int k = in.nextInt();
		myAssert(between(1, n, 100), "n is out of bounds");
		myAssert(between(1, k, 1000), "n is out of bounds");
		int ans = k;
		for (int i= 0; i < n; i++) {
			int a = in.nextInt();
			int b = in.nextInt();
			myAssert(between(0, a, k), "a_{" + i + "} is out of bounds");
			myAssert(between(0, b, k), "b_{" + i + "} is out of bounds");
			myAssert(between(0, a + b, k), "a_{" + i + "} + " + "b_{" + i + "}" + " is out of bounds");
			if (k - ans >= b) {
				ans = Math.min(ans + a, k - b);
			} else {
				ans = k - b;
			}
		}
		out.println(ans);
	}

}
