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