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