#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); ++i) {
    if (!first) {
      res += ",";
    }
    first = 0;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; ++i) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ",";
    }
    first = 0;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + "," + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + "," + to_string(get<1>(p)) + "," +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + "," + to_string(get<1>(p)) + "," +
         to_string(get<2>(p)) + "," + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  vector<long long> sumA(n + 1, 0);
  vector<long long> sumB(n + 1, 0);
  vector<vector<long long>> dp(n + 1, vector<long long>(k, -1));
  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    sumA[i] = sumA[i - 1] + a[i - 1];
    sumB[i] = sumB[i - 1] + b[i - 1];
    for (int j = 0; j < k; ++j) {
      if (dp[i - 1][j] != -1) {
        long long sum = sumA[i - 1] + sumB[i - 1];
        sum -= dp[i - 1][j] * k;
        dp[i][(j + a[i - 1]) % k] =
            max(dp[i][(j + a[i - 1]) % k],
                dp[i - 1][j] + (j + a[i - 1]) / k + (sum - j + b[i - 1]) / k);
        for (int s = max(1, k - b[i - 1]); s <= min(k - 1, a[i - 1]); ++s) {
          dp[i][((j - s + a[i - 1]) % k + k) % k] =
              max(dp[i][((j - s + a[i - 1]) % k + k) % k],
                  dp[i - 1][j] + 1 + (a[i - 1] + j - s) / k +
                      (sum - j + b[i - 1] - (k - s)) / k);
        }
      }
    }
  }
  42;
  long long mx = 0;
  for (int i = 0; i < k; ++i) {
    mx = max(mx, dp[n][i]);
  }
  cout << mx << endl;
  return 0;
}
