#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, a, b;
  cin >> n >> k;
  int p = 0;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    p += abs(a - b) + 1;
  }
  if (p % k == 0)
    cout << 0 << endl;
  else
    cout << k - (p % k) << endl;
}
