#include <iostream>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int dirty = 0;
for (int i = 0; i < n; ++i) {
int wash, not_wash; //кол-во моющих и не моющих за собой постояльцев
cin >> wash >> not_wash;
if (not_wash < dirty) {
int free_dirty = dirty - not_wash; //оставшиеся грязные тарелки
dirty -= min(wash, free_dirty);
}
else
if (not_wash > dirty)
dirty = not_wash;
}
cout << k - dirty;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgbWFpbigpIHsKICAgIGludCBuLCBrOwogICAgY2luID4+IG4gPj4gazsKICAgIGludCBkaXJ0eSA9IDA7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkgewogICAgICAgIGludCB3YXNoLCBub3Rfd2FzaDsgLy/QutC+0Lst0LLQviDQvNC+0Y7RidC40YUg0Lgg0L3QtSDQvNC+0Y7RidC40YUg0LfQsCDRgdC+0LHQvtC5INC/0L7RgdGC0L7Rj9C70YzRhtC10LIKICAgICAgICBjaW4gPj4gd2FzaCA+PiBub3Rfd2FzaDsKICAgICAgICBpZiAobm90X3dhc2ggPCBkaXJ0eSkgewogICAgICAgICAgICBpbnQgZnJlZV9kaXJ0eSA9IGRpcnR5IC0gbm90X3dhc2g7IC8v0L7RgdGC0LDQstGI0LjQtdGB0Y8g0LPRgNGP0LfQvdGL0LUg0YLQsNGA0LXQu9C60LgKICAgICAgICAgICAgZGlydHkgLT0gbWluKHdhc2gsIGZyZWVfZGlydHkpOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgaWYgKG5vdF93YXNoID4gZGlydHkpCiAgICAgICAgICAgIGRpcnR5ID0gbm90X3dhc2g7CiAgICB9CiAgICBjb3V0IDw8IGsgLSBkaXJ0eTsKICAgIHJldHVybiAwOwp9