#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  long long ans = 0;
  for (int i = (int)0; i < (int)n; ++i) {
    long long l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }
  int ted = 0;
  while (ans % k) {
    ted++;
    ans++;
  }
  cout << ted << endl;
}
