#include <bits/stdc++.h>
using namespace std;
int l[100005], r[100005];
int main(int argc, char* argv[]) {
  std::ios::sync_with_stdio(false);
  int n, k;
  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 res = 0;
  while (sum % k != 0) {
    sum++;
    res++;
  }
  printf("%d\n", res);
  return 0;
}
