#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int i = n, ni, nj;
  int count = 0;
  while (i--) {
    scanf("%d%d", &ni, &nj);
    count = count + nj - ni + 1;
  }
  if (!(count % k))
    printf("0\n");
  else
    printf("%d\n", k - (count % k));
  return 0;
}
