#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 7;
const int INF = ~0U >> 1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
int n, k;
int u, v;
int main() {
  cin >> n >> k;
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    cin >> u >> v;
    res += (v - u + 1);
  }
  long long ans = res % k;
  if (ans == 0)
    cout << "0" << endl;
  else
    cout << k - ans << endl;
  return 0;
}
