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

/**
 * @author Roman V Satyukov
 */
public class fitness_rs implements Runnable {
	private final String problemID = getClass().getName().split("_")[0].toLowerCase();
	private BufferedReader in;
	private PrintWriter out;
	
	private void check(boolean expr, String message) {
		if (!expr) {
			throw new AssertionError(message);
		}
	}
	
	private void solve() throws IOException {
		StringTokenizer st = new StringTokenizer(in.readLine());
		int n = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());
		check((1 <= n) && (n <= 100), "n is not in [1..100]");
		check((1 <= k) && (k <= 1000), "k is not in [1..1000]");
		int t = 0;
		for (int i = 0; i < n; i++) {
			st = new StringTokenizer(in.readLine());
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			check((0 <= a) && (0 <= b), "Some of a[i] and b[i] is less than zero");
			check((a + b) <= k, "Sum of some a[i] and b[i] is greater than k");
			t = Math.max(b, t - a);
		}
		out.println(k - t);
	}
	
	public static void main(String[] args) {
		new Thread(new fitness_rs()).start();
	}

	public void run() {
		try {
			in = new BufferedReader(new FileReader(new File(problemID + ".in")));
			out = new PrintWriter(new File(problemID + ".out"));
			solve();
			in.close();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}
