#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, x, y, total_num = 0;
  cin >> n >> k;
  while (n--) {
    cin >> x >> y;
    total_num += (y - x) + 1;
  }
  if (total_num % k)
    cout << (k - (total_num % k)) % k << endl;
  else
    cout << 0 << endl;
  return 0;
}
