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