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