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