#include <bits/stdc++.h>
using namespace std;
bool debug = false;
long long a[1000];
long long b[1000];
bool dp[600][600];
void solve() {
  long long n, k;
  cin >> n >> k;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    sum += a[i] + b[i];
  }
  long long res = 0;
  dp[0][0] = true;
  for (int i = 1; i <= n; i++) {
    for (int x = 0; x < k; x++) {
      dp[i][x] = dp[i - 1][(x - a[i] % k + k) % k];
      for (int t = 0; t <= min(k - 1, a[i]); t++) {
        if ((a[i] - t) % k + b[i] >= k) {
          dp[i][x] |= dp[i - 1][(x - t + k) % k];
        }
      }
    }
  }
  long long min = INT_MAX;
  for (int x = k - 1; x >= 0; x--) {
    if (dp[n][x]) min = x;
  }
  cout << (sum - min) / k << endl;
}
int main() {
  std::ios::sync_with_stdio(false);
  solve();
  return 0;
}
