#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

ll N, D;
vector<ll> ts, fs;
int main(void) {
	cin >> N >> D;
	ll ans = 0, dnow = 0;
	ll tp = 0, fp = 1;
	for (int i = 0; i < N; i++) {
		int t, f;
		cin >> t >> f;
		int dt = t - tp, df = abs(f - fp);
		if (dt < df) {
			ans = -1;
			break;
		}
		int roundtime = fp + f - 2;
		if (dt >= roundtime) { // take down, d to 0
			ans += (fp - 1) * dnow;
			dnow = 1;
		} else { // go next
			if (dnow == D) {
				ans = -1;
				break;
			}
			ans += dt * dnow;
			dnow++;
		}
		tp = t;
		fp = f;
	}
	if (ans != -1) ans += (fp - 1) * dnow;
	cout << ans << endl;
}