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