#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[510], b[510];
bool dp[510][510];
long long sum = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i] >> b[i], sum += a[i] + b[i];
  dp[0][0] = true;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      dp[i][j] |= dp[i - 1][((j - a[i]) % k + k) % k];
      for (int l = 0; l <= min(k - 1, a[i]); l++) {
        if ((a[i] - l) % k + b[i] >= k)
          dp[i][j] |= dp[i - 1][((j - l) % k + k) % k];
      }
    }
  }
  for (int i = 0; i < k; i++)
    if (dp[n][i]) {
      cout << (sum - i) / k << "\n";
      break;
    }
  return 0;
}
