const int NMAX = 505;
int N, K, a[NMAX], b[NMAX];
bool dp[NMAX][NMAX];
int main()
{
#ifndef ONLINE_JUDGE
ifstream cin("test.in");
#endif
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#endif
long long sum = 0, answer = 0;
cin >> N >> K;
for (int i = 1; i <= N; ++i)
{
cin >> a[i] >> b[i];
sum += a[i] + b[i];
}
dp[0][0] = true;
for (int i = 1; i <= N; ++i)
{
for (int j = 0; j < K; ++j)
{
dp[i][j] = dp[i - 1][(j - a[i] % K + K) % K];
for (int l = 0; l <= min(K - 1, a[i]); ++l)
{
if ((a[i] - l) % K + b[i] >= K)
dp[i][j] |= dp[i - 1][(j - l + K) % K];
}
}
}
for (int i = 0; i < K; ++i)
if (dp[N][i] == true)
answer = max(answer, (sum - i) / K);
cout << answer << "\n";
return 0;
}