#include<stdio.h>
using namespace std;
int main() {
int n = 0, k = 0;
scanf("%i", &n);
scanf("%i", &k);
int xTotal = 0;
for (int i = 0; i < n; i++) {
// initalize left and right for this segment
int l, r;
scanf("%i", &l);
scanf("%i", &r);
int x = (r-l)+1; // calculate how many nums are (x) (the value of this current set)
xTotal+=x;
}
// find the nearest number divisible by k
int currentNumber = xTotal;
while (currentNumber%k != 0) {
currentNumber++; // only increment since the only moves we can do is increase (l-1, r+1)
}
printf("%i", currentNumber-xTotal);
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAppbnQgbWFpbigpIHsKICAgIGludCBuID0gMCwgayA9IDA7CiAgICAKICAgIHNjYW5mKCIlaSIsICZuKTsKICAgIHNjYW5mKCIlaSIsICZrKTsKCiAgICBpbnQgeFRvdGFsID0gMDsKIAogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICAvLyBpbml0YWxpemUgbGVmdCBhbmQgcmlnaHQgZm9yIHRoaXMgc2VnbWVudAogICAgICAgIGludCBsLCByOwogICAgICAgIHNjYW5mKCIlaSIsICZsKTsKICAgICAgICBzY2FuZigiJWkiLCAmcik7CgogICAgICAgIGludCB4ID0gKHItbCkrMTsgLy8gY2FsY3VsYXRlIGhvdyBtYW55IG51bXMgYXJlICh4KSAodGhlIHZhbHVlIG9mIHRoaXMgY3VycmVudCBzZXQpCiAgICAgICAgeFRvdGFsKz14OwogICAgfQogCiAgICAvLyBmaW5kIHRoZSBuZWFyZXN0IG51bWJlciBkaXZpc2libGUgYnkgawogICAgCiAgICBpbnQgY3VycmVudE51bWJlciA9IHhUb3RhbDsKICAgIHdoaWxlIChjdXJyZW50TnVtYmVyJWsgIT0gMCkgewogICAgICAgIGN1cnJlbnROdW1iZXIrKzsgLy8gb25seSBpbmNyZW1lbnQgc2luY2UgdGhlIG9ubHkgbW92ZXMgd2UgY2FuIGRvIGlzIGluY3JlYXNlIChsLTEsIHIrMSkKICAgIH0KIAogICAgcHJpbnRmKCIlaSIsIGN1cnJlbnROdW1iZXIteFRvdGFsKTsKIAogICAgcmV0dXJuIDA7Cn0=