#include <bits/stdc++.h>
int main() {
  long n, k, l, r;
  long a = 0;
  scanf("%ld%ld", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%ld%ld", &l, &r);
    a += (r - l + 1);
  }
  if (a % k == 0)
    printf("0");
  else
    printf("%ld", k - (a % k));
  return 0;
}
