#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const int MAX = 510;
long long dp[MAX][MAX], pref[MAX];
int a[MAX], b[MAX];
int n, k;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    if (i) pref[i] += pref[i - 1];
    pref[i] += a[i] + b[i];
  }
  for (int i = n - 1; i + 1; i--)
    for (int j = 0; j < k; j++) {
      long long add = 0;
      if (i) add = pref[i - 1];
      int resto = (add - j + k) % k;
      long long ans = dp[i + 1][(j + a[i]) % k];
      ans += (j + a[i]) / k;
      ans += (resto + b[i]) / k;
      for (int p = 1; p <= min(k - 1, a[i]); p++)
        if (k - p <= b[i]) {
          long long nxt = 1 + dp[i + 1][(j + a[i] - p) % k];
          nxt += (j + a[i] - p) / k;
          nxt += (resto + b[i] - (k - p)) / k;
          ans = max(ans, nxt);
        }
      dp[i][j] = ans;
    }
  cout << dp[0][0] << '\n';
  exit(0);
}
