#include using namespace std; const int _ = 1e5 + 9; long long n, m; long long a[_], b[_], flg[_]; long long tot, ans1, ans2, pos; int main() { freopen("remake.in", "r", stdin); freopen("remake.out", "w", stdout); ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for(int i = 1;i <= n;i++) { cin >> a[i] >> b[i]; if(a[i] > 0) tot += (m - 1) * a[i]; else if(b[i] >= (m - 1) * a[i]) tot += b[i], flg[i] = 1; else tot += (m - 1) * a[i]; if(tot > ans1) ans1 = tot, pos = i; } for(int i = pos + 1;i <= n;i++) flg[i] = 0; tot = 0; for(int i = 1;i <= n;i++) { if(a[i] > 0) tot += max(a[i], b[i]); else if(flg[i]) tot += 0; else tot += max(a[i], b[i]); ans2 = max(ans2, tot); } cout << ans1 + ans2; return 0; }