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

public class fitness_aa implements Runnable {

	public static void main(String[] args) {
		new Thread(new fitness_aa()).start();
	}

	BufferedReader br;

	StringTokenizer st;

	PrintWriter out;

	boolean eof = false;

	Random rand = new Random(this.hashCode());

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			br = new BufferedReader(new FileReader(FNAME + ".in"));
			out = new PrintWriter(FNAME + ".out");
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(566);
		}
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "0";
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	void MyAssert(boolean u, String message) {
		if (!u) {
			throw new Error("Assertion failed!!! " + message);
		}
	}

	void inBounds(long x, long l, long r, String name) {
		MyAssert(l <= x && x <= r, name + " is not in bounds!!! " + x
				+ " is not in [" + l + ", " + r + "]");
	}

	String FNAME = "fitness";

	private void solve() throws IOException {
		int n = nextInt();
		inBounds(n, 1, 100, "n");
		int k = nextInt();
		inBounds(k, 1, 1000, "k");
		int open = 0;
		for (int i = 0; i < n; i++) {
			int a = nextInt();
			int b = nextInt();
			inBounds(a, 0, k, "a[" + i + "]");
			inBounds(b, 0, k, "b[" + i + "]");
			inBounds(a + b, 0, k, "a[" + i + "] + b[" + i + "]");
			open = Math.max(b, open);
			int c = Math.min(open - b, a);
			open -= c;
		}
		out.println(k - open);
	}

}
