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