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