#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c = 0, d, i, j, n, m;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    c += (b - a) + 1;
  }
  d = 0;
  while (c % m != 0) {
    d++;
    c++;
  }
  cout << d << endl;
  return 0;
}
