#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e2 + 7;
int a[maxn], b[maxn];
long long dp[maxn][maxn];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      if (dp[i][j] >= 0) {
        int b1 = sum - dp[i][j] * k - j;
        for (int s1 = 1; s1 <= a[i] && s1 < k; s1++) {
          if (b[i] + s1 >= k) {
            int a2 = j + a[i] - s1;
            int b2 = b1 + b[i] - (k - s1);
            dp[i + 1][a2 % k] =
                max(dp[i + 1][a2 % k], dp[i][j] + a2 / k + b2 / k + 1);
          }
        }
        dp[i + 1][(j + a[i]) % k] =
            max(dp[i + 1][(j + a[i]) % k],
                dp[i][j] + (j + a[i]) / k + (b1 + b[i]) / k);
      }
    }
    sum += (a[i] + b[i]);
  }
  long long ans = -1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= k; j++) ans = max(ans, dp[i][j]);
  }
  cout << ans << endl;
  return 0;
}
