#include <bits/stdc++.h>
using namespace std;
const int maxn = 500 + 5;
int n, m, a[maxn], b[maxn];
int numy[maxn][maxn];
long long ans, dp[2][maxn];
signed main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d%d", a + i, b + i);
  memset(numy, 128, sizeof(numy));
  for (int i = 0; i <= n; i++) numy[i][0] = 0;
  int now = 1, pre = 0;
  for (int i = 1; i <= n; i++) {
    swap(now, pre);
    for (int j = 0; j < m; j++) {
      int lx = j, ly = numy[i - 1][j];
      if (ly < 0) continue;
      for (int k = 0; k < m; k++) {
        int x = k;
        if (x > a[i]) continue;
        long long tmp = (a[i] - k + b[i]) / m;
        int y = min(b[i], (a[i] - k + b[i]) % m);
        long long tmp1 = (lx + x) / m;
        int nx = (lx + x) % m;
        long long tmp2 = (ly + y) / m;
        int ny = (ly + y) % m;
        if (dp[now][nx] < dp[pre][lx] + tmp + tmp1 + tmp2) {
          dp[now][nx] = dp[pre][lx] + tmp + tmp1 + tmp2;
          numy[i][nx] = ny;
        }
        if (dp[now][nx] == dp[pre][lx] + tmp + tmp1 + tmp2 &&
            ny > numy[i][nx]) {
          dp[now][nx] = dp[pre][lx] + tmp + tmp1 + tmp2;
          numy[i][nx] = ny;
        }
        ans = max(ans, dp[now][nx]);
      }
    }
  }
  printf("%lld\n", ans);
}
