#include <bits/stdc++.h>
int main() {
  int n, k, num, s, i;
  scanf("%d%d", &n, &k);
  int l[n], r[n];
  for (i = 0, s = 0; i < n; i++) {
    scanf("%d %d", &l[i], &r[i]);
    s = s + (r[i] - l[i]) + 1;
  }
  if (s % k == 0)
    printf("0");
  else {
    num = s / k;
    num = k * (num + 1);
    printf("%d", num - s);
  }
}
