#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353, N = 510;
const long long inf = 1e15;
int n, k, a[N], b[N];
long long f[N][N];
inline int addMod(int a, int b) { return (a += b) >= mod ? a - mod : a; }
inline long long quickpow(long long base, long long pw) {
  long long ret = 1;
  while (pw) {
    if (pw & 1) ret = ret * base % mod;
    base = base * base % mod, pw >>= 1;
  }
  return ret;
}
template <class T>
inline void read(T &x) {
  x = 0;
  char ch = getchar(), w = 0;
  while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x = w ? -x : x;
  return;
}
int main() {
  read(n), read(k);
  for (register int i = 1; i <= n; ++i) read(a[i]), read(b[i]);
  for (register int i = 0; i <= n; ++i)
    for (register int j = 0; j < k; ++j) f[i][j] = -inf;
  f[0][0] = 0;
  int s = 0;
  for (register int i = 0; i < n; ++i) {
    int w = (a[i + 1] + b[i + 1]) / k, r = (a[i + 1] + b[i + 1]) % k;
    for (register int j = 0; j < k; ++j) {
      int p = (s - j + k) % k;
      for (register int u = 0; u < k; ++u) {
        if (a[i + 1] < u) continue;
        if (u <= r && u + b[i + 1] >= r) {
          int x = (j + u) / k, y = (p + r - u) / k;
          f[i + 1][(j + u) % k] =
              max(f[i + 1][(j + u) % k], f[i][j] + w + x + y);
        }
        if (u > r && u + b[i + 1] >= r + k) {
          int x = (j + u) / k, y = (p + r + k - u) / k;
          f[i + 1][(j + u) % k] =
              max(f[i + 1][(j + u) % k], f[i][j] + w - 1 + x + y);
        }
      }
    }
    s = (s + r) % k;
  }
  long long ans = 0;
  for (register int i = 0; i < k; ++i) ans = max(ans, f[n][i]);
  cout << ans << endl;
  return 0;
}
