#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 110000

int N, M;
int a, b;
int A[MAX], B[MAX];
int hoge[MAX][4] = {};
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int ans = 0, temp, num = 0, x = 0, y = 0;
	
	
	cin>>N>>M;
	
	// hoge[0][0] = -INF;
	
	for(int i = 0; i < N; i++){
		cin>>a>>b;
		
		if(a >= 0 && b >= 0){
			if(a >= b) temp = a*M;
			else temp = a*(M-1)+b;
		} else if(a >= 0 && b < 0){
			temp = a*M;
		} else if(a < 0 && b >= 0){
			temp = b;
		} else {
			if(b >= a*M){
				temp = b;
			} else {
				temp = a*M;
			}
		}
		if(!i){
			x = temp;
			y = max(a,b);
			continue;
		}
		
		hoge[i+1][2] += temp+hoge[i][2];
		
		hoge[i+1][1] = max(hoge[i][2],hoge[i][1]) + max(a,b);
		
		hoge[i+1][0] = max(hoge[i][0],max(hoge[i][2],hoge[i][1]));
		// else hoge[i+1][0] = -INF;
		
		// cout<<temp<<" "<<max(a,b)<<endl;
		// cout<<hoge[i+1][0]<<" "<<hoge[i+1][1]<<" "<<hoge[i+1][2]<<endl;
	}
	
	// ans = max(hoge[N][0],max(hoge[N][2],hoge[N][1]));
	ans = max(hoge[N][0]+x,max(hoge[N][2]+x,hoge[N][1]+x));
	
	cout<<ans<<endl;
	
	return 0;
}