#include<iostream>
#include<algorithm>

using namespace std;

int x[100'000];
int v[100'000];
bool eaten[100'000];

int distance(int nowX, targetX, int halfC){
	int distance = abs(targetX - nowX) % halfC;
	return distance;
}

int main(){
	int n, c;
	cin >> n >> c;
	int ans = 0;
	int halfC = c/2;

	for(int i = 0; i < n; ++i){
		cin >> x[i] >> v[i];
		eaten[i] = false;
	}

	// if(distance >= cal) eat
	int nowX = 0;
	int eatIndex, maxCal;
	bool shallContinue = true;

	while(shallContinue){
		shallContinue = false;
		eatIndex = maxCal = -1;
		for(int i = 0; i < n; ++i){
			if(eaten[i]) continue;
			int d = distance(nowX, x[i], halfC);
			int cal = v[i] - d;
			if(cal < 0) continue;
			if(cal > maxCal){
				eatIndex = i;
				maxCal = cal;
			}
		}
		if(eatIndex != -1){
			ans += maxCal;
			shallContinue = true;
			eaten[eatIndex] = true;
		}
	}

	cout << ans << endl;
	return 0;
}