#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  int count = 0;
  cin >> n >> k;
  while (n--) {
    int a, b;
    cin >> a >> b;
    count += (b - a) + 1;
  }
  int moves = 0;
  while (count % k != 0) {
    count += 1;
    moves += 1;
  }
  cout << moves << endl;
  return 0;
}
