#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int f[N][N], n, k, a[N], b[N];
long long ans, sa, sb;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &a[i], &b[i]), sa += a[i], sb += b[i];
  memset(f, -1, sizeof(f));
  f[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    memcpy(f[i], f[i - 1], sizeof(f[i]));
    for (int s = 0; s < k; s++)
      if (~f[i - 1][s])
        for (int j = 0; j < k; j++)
          if (j <= a[i] && k - j <= b[i])
            if (f[i][(s + j) % k] == -1)
              f[i][(s + j) % k] = f[i - 1][s] + 1;
            else
              f[i][(s + j) % k] = min(f[i][(s + j) % k], f[i - 1][s] + 1);
  }
  ans = sa / k + sb / k;
  for (int i = 0; i < k; i++)
    if (f[n][i] != -1 && f[n][i] != 0)
      ans = max(ans, 1 + (sa - i) / k + (sb - (k - i)) / k);
  printf("%I64d\n", ans);
  return 0;
}
