#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
const double pi = 3.141592653589793238462643383279502884197169399375105;
set<int> st;
vector<pair<int, int>> vp;
map<char, long long> mpx;
map<long long, string> mpy;
int farr[N];
vector<int> v;
vector<long long> v1(11, 0);
vector<int> v2(210, 0);
vector<long long> v3(10, 0);
priority_queue<int> pq;
vector<bool> Count_Primes_seive(int n) {
  vector<bool> primes(n + 1, 1);
  int cnt = 0;
  primes[0] = primes[1] = 0;
  for (int i = 2; i <= n; i++) {
    if (primes[i]) {
      cnt++;
      for (int j = i + i; j <= n; j += i) primes[j] = 0;
    }
  }
  return primes;
}
int main() {
  int n, k, l, r, num = 0, cnt = 0;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> l >> r;
    num += r - l + 1;
  }
  while (num % k != 0) {
    num++;
    cnt++;
  }
  cout << cnt;
  return 0;
}
