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