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