#include <bits/stdc++.h>
int n, k;
int l[100050], r[100050];
int ans;
int main() {
  scanf("%d%d", &n, &k);
  int sum = 0;
  for (int i = (0); i != (n); i++) {
    scanf("%d%d", l + i, r + i);
    sum += r[i] - l[i] + 1;
  }
  int m = sum % k;
  ans = m ? k - m : 0;
  printf("%d\n", ans);
  return 0;
}
