#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[1000000], n, dist = 0, k, co = 0;
  cin >> n >> k;
  for (int i = 0; i < n * 2; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n * 2; i += 2) {
    dist += abs(arr[i + 1] - arr[i]) + 1;
  }
  while (true) {
    if (dist % k == 0) {
      cout << co;
      return 0;
    } else {
      dist += 1;
      co++;
    }
  }
}
