#include <bits/stdc++.h>
const int N = 505;
int n, k, a[N], b[N];
long long dp[N][N];
int main() {
  scanf("%d%d", &n, &k);
  memset(dp, -1, sizeof(dp));
  for (register int i = 1; i <= n; i++) scanf("%d%d", a + i, b + i);
  dp[1][0] = 0;
  long long ans = 0, sum = 0;
  for (register int i = 1; i <= n; i++) {
    for (register int j = 0; j < k; j++)
      if (~dp[i][j]) {
        int bv = sum - dp[i][j] * k - j + b[i], val;
        for (register int xa = 0; xa <= std::min(k, a[i]); xa++) {
          int xb = k - xa, sa = j + a[i] - xa, sb = bv - xb;
          val = sa % k;
          if (b[i] - xb >= 0) {
            dp[i + 1][val] = (dp[i + 1][val] < dp[i][j] + 1 + sa / k + sb / k
                                  ? dp[i][j] + 1 + sa / k + sb / k
                                  : dp[i + 1][val]);
            ans = (ans < dp[i + 1][val] ? dp[i + 1][val] : ans);
          }
        }
        val = (j + a[i]) % k;
        dp[i + 1][val] = (dp[i + 1][val] < dp[i][j] + (j + a[i]) / k + bv / k
                              ? dp[i][j] + (j + a[i]) / k + bv / k
                              : dp[i + 1][val]);
        ans = (ans < dp[i + 1][val] ? dp[i + 1][val] : ans);
      }
    sum += a[i] + b[i];
  }
  printf("%lld", ans);
}
