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