#include using namespace std; using ll = long long; template inline bool chmin(T &a, const U &b) { return a > b ? a = b, true : false; } const ll INF = 1e15; void main_() { int n,d; cin >> n >> d; vector a(n), b(n); vector> c(n); ll sum = 0; ll cnt = 0; for(int i = 0; i < n; i++){ cin >> a[i] >> b[i]; sum += a[i]; cnt += (b[i] + d - 1)/d * a[i]; c[i].first = b[i]; c[i].second = a[i]; } sort(c.begin(),c.end()); ll threshold = n; for(int i = 0; i < n; i++){ if(sum < d){ threshold = i; break; } sum -= c[i].second; } set s; s.insert(threshold); s.insert(max(0LL,threshold-1)); ll ans = INF; for(auto x:s){ ll sub = 0; if(x)sub = c[x-1].first; ll total = sub; vector> r; for(int i = x; i < n; i++){ if(c[i].first <= sub)continue; total += (c[i].first - sub + d - 1) / d * c[i].second; pair r_cand; r_cand.first = (c[i].first - sub) % d; if(r_cand.first == 0)r_cand.first = d; r_cand.second = i; r.push_back(r_cand); } sort(r.begin(),r.end()); ll p = 0; chmin(ans,total); for(auto y:r){ total += y.first - p; p = y.first; total -= c[y.second].second; chmin(ans,total); } } cout << ans << endl; }; int main() { int t = 1; // cin >> t; while(t--) main_(); return 0; }