#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, x;
  int ar[2];
  x = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> ar[0] >> ar[1];
    x += ar[1] - ar[0] + 1;
  }
  x = x % k;
  if (x)
    cout << k - x << '\n';
  else
    cout << "0";
  return 0;
}
