#include <bits/stdc++.h>
int main() {
  int n, k, i, j, z = 0, x, y;
  scanf("%d %d", &n, &k);
  int a[n][2];
  for (i = 0; i < n; i++)
    for (j = 0; j < 2; j++) scanf("%d", &a[i][j]);
  for (i = 0; i < n; i++) z = z + (a[i][1] - a[i][0]) + 1;
  x = z % k;
  if (x != 0)
    y = k - x;
  else
    y = x;
  printf("\n %d", y);
  return 0;
}
