#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, icount = 0, sum = 0;
  cin >> n >> k;
  while (n--) {
    int x, y;
    cin >> x >> y;
    int f = abs(x - y) + 1;
    sum += f;
  }
  while (sum % k != 0) {
    ++sum;
    ++icount;
  }
  cout << icount;
  return 0;
}
