#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
bool dp[501][501];
long long a[501], b[501];
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i < n + 1; i++) {
    cin >> a[i] >> b[i];
  }
  dp[0][0] = true;
  long long tot = 0;
  for (long long i = 1; i < n + 1; i++) {
    tot += (a[i] + b[i]);
    for (long long j = 0; j < min(k, a[i] + 1); j++) {
      long long x = (a[i] - j) % k;
      if (x + b[i] < k) continue;
      for (long long l = 0; l < k; l++) {
        if (!dp[i - 1][l]) continue;
        long long rem = (l + j) % k;
        dp[i][rem] = true;
      }
    }
    long long j = a[i] % k;
    for (long long l = 0; l < k; l++) {
      if (!dp[i - 1][l]) continue;
      long long rem = (l + j) % k;
      dp[i][rem] = true;
    }
  }
  for (long long i = 0; i < k; i++) {
    if (dp[n][i]) {
      long long ans = (tot - i) / k;
      cout << ans;
      return 0;
    }
  }
  return 0;
}
