#include <bits/stdc++.h>
const int N = 5e2;
int n, k;
long long a[N + 5], b[N + 5], sumA[N + 5], sumB[N + 5], f[N + 5][N + 5];
void prev(int &x) { (x-- == 0) && (x = k - 1); }
void chkmax(long long &x, const long long &y) { (x < y) && (x = y); }
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld", &a[i], &b[i]);
  }
  std::partial_sum(a + 1, a + n + 1, sumA + 1);
  std::partial_sum(b + 1, b + n + 1, sumB + 1);
  memset(f, -0x7f, sizeof(f));
  f[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int resA = 0, resB = (sumA[i] + sumB[i]) % k; resA < k;
         resA++, prev(resB)) {
      if (f[i][resA] < 0 || resA > sumA[i] || resB > sumB[i]) {
        continue;
      }
      for (int p = 0, q = 0; p < k; p++, prev(q)) {
        if (p > a[i + 1] || q > b[i + 1]) {
          continue;
        }
        int curA = a[i + 1] - p, curB = b[i + 1] - q;
        chkmax(f[i + 1][(resA + curA) % k],
               f[i][resA] + (p + q == k) + curA / k + curB / k +
                   ((resA + curA % k) >= k) + ((resB + curB % k) >= k));
      }
    }
  }
  printf("%lld\n", *std::max_element(f[n], f[n] + k));
  return 0;
}
