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