#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  int n, k, value = 0;
  vector<pair<int, int>> set;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    set.push_back({x, y});
  }
  for (int i = 0; i < n; ++i) {
    value += set[i].second - set[i].first + 1;
  }
  if (value % k == 0) {
    cout << 0;
    return 0;
  }
  cout << k - (value % k);
}
