#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); 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]; } ll threshold = n; for(int i = 0; i < n; i++){ if(sum < d){ threshold = i; break; } sum -= a[i]; } set s; s.insert(threshold); s.insert(max(0LL,threshold-1)); ll ans = INF; for(auto x:s){ ll sub = 0; if(threshold)sub = b[threshold-1]; ll total = sub; vector> r; for(int i = threshold; i < n; i++){ if(b[i] <= sub)continue; total += (b[i] - sub + d - 1) / d * a[i]; pair r_cand; r_cand.first = (b[i] - 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 x:r){ total += x.first - p; p = x.first; total -= a[x.second]; chmin(ans,total); } } cout << ans << endl; }; int main() { int t = 1; // cin >> t; while(t--) main_(); return 0; }