#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair pll; typedef pair pi; typedef pair pd; typedef pair pdl; #define F first #define S second const ll E=1e18+7; const ll MOD=1000000007; int main(){ ll n,m; cin>>n>>m; vector A(n); ll ans=-E; ll sum=0; ll meat=0; ll egg=0; for(auto &I:A){cin>>I.F>>I.S;} for(auto &I:A){ meat+=max(I.F,I.S); if(I.F<0 && I.F>I.S){sum+=max(I.F*m-I.F,I.S-I.F);} else{sum+=I.F*(m-1);} if(sum>egg){egg=sum;} ans=max(ans,egg+meat); } cout<