#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, a, b;
  while (cin >> n >> k) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      cin >> a >> b;
      cnt += (b - a + 1);
    }
    if (cnt % k == 0)
      cout << 0 << endl;
    else {
      cnt = cnt % k;
      cout << k - cnt << endl;
    }
  }
  return 0;
}
