#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
long long n, k, a[MAXN], b[MAXN], sum[MAXN], dp[MAXN][MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    sum[i] = (sum[i - 1] + a[i] + b[i]) % k;
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= k; j++) {
      dp[i][j] = -1;
    }
  }
  dp[0][0] = 0;
  for (long long i = 0; i < n; i++) {
    for (long long red = 0; red < k; red++) {
      if (dp[i][red] == -1) {
        continue;
      }
      long long blue = (sum[i] - red + k) % k;
      long long aval = a[i + 1], bval = b[i + 1];
      dp[i + 1][(red + aval) % k] =
          max(dp[i + 1][(red + aval) % k],
              dp[i][red] + (red + aval) / k + (blue + bval) / k);
      if (aval + bval >= k) {
        for (long long tr = 0; tr <= min(k, aval); tr++) {
          long long tb = k - tr, nr = (red + aval - tr) % k;
          if (tb > bval) continue;
          dp[i + 1][nr] =
              max(dp[i + 1][nr], dp[i][red] + 1 + (red + aval - tr) / k +
                                     (blue + bval - tb) / k);
          if (i == 0 &&
              dp[i][red] + 1 + (red + aval - tr) / k + (blue + bval - tb) / k ==
                  2) {
          }
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < k; i++) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans << '\n';
  return 0;
}
