#include <bits/stdc++.h>
using namespace std;
const int N = 5e2 + 10;
const int mod = 1e9 + 7;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0', c = getchar();
  return x * f;
}
long long dp[N][N];
long long sum[N];
int a[N], b[N];
int main() {
  int n = read(), k = read();
  for (int i = 1; i <= n; i++)
    a[i] = read(), b[i] = read(), sum[i] = sum[i - 1] + a[i] + b[i];
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= k; j++) dp[i][j] = -1e18;
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    int p = (a[i] + b[i]) % k;
    for (int j = 0; j < k; j++) {
      if (dp[i - 1][j] == -1e18) continue;
      int lx = j;
      int ly = sum[i - 1] - k * dp[i - 1][j] - j;
      for (int x = 0; x < k; x++) {
        int y;
        if (x <= p)
          y = p - x;
        else
          y = p + k - x;
        if (x <= a[i] && y <= b[i]) {
          int xx = (x + lx) % k;
          int yy = (y + ly) % k;
          dp[i][xx] = max(dp[i][xx], dp[i - 1][j] + (a[i] + b[i] - x - y) / k +
                                         (x + lx) / k + (y + ly) / k);
        }
      }
    }
  }
  long long ans = -1e18;
  for (int i = 0; i <= k; i++) ans = max(dp[n][i], ans);
  printf("%lld\n", ans);
}
