#include <bits/stdc++.h>
using namespace std;
const int maxn = 510;
long long a[maxn], b[maxn];
long long dp[2][maxn] = {0};
int main() {
  long long n, k;
  cin >> n >> k;
  long long suma = 0, sumb = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    suma += a[i];
    sumb += b[i];
  }
  long long ans = suma / k + sumb / k;
  long long x = 0;
  dp[0][0] = 1;
  for (long long i = 0; i < n; i++) {
    memcpy(dp[x ^ 1], dp[x], sizeof(dp[x]));
    x ^= 1;
    for (long long j = 0; j < k; j++) {
      if (!dp[x ^ 1][j]) continue;
      for (long long u = 1; u <= min(a[i], k); u++) {
        if (u + b[i] < k) continue;
        dp[x][(j + u) % k] = 1;
      }
    }
  }
  for (long long i = 1; i < k; i++) {
    if (dp[x][i]) ans = max(ans, (suma - i) / k + (sumb + i) / k);
  }
  cout << ans << endl;
  return 0;
}
