#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, D;
	cin >> N >> D;
	vector<int> T(N);
	vector<int> F(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> T[i] >> F[i];
	}
	int curf = 1;
	int curt = 0;
	int curn = 0;
	bool f = true;
	for (int i = 0; i < N; i++) {
		if (abs(curf - F[i]) <= T[i] - curt) {
			if (curf + F[i]-2 <= T[i] - curt) {
				res += curn*(curf - 1);
				curn = 1;
			}
			else {
				res += curn * (T[i] - curt);
				curn++;
			}
		}
		else {
			f = false;
			break;
		}
		curt = T[i];
		curf = F[i];
		if (curn > D) {
			f = false;
			break;
		}
	}
	res += curn * (curf - 1);
	if (f) {
		cout << res << endl;
	}
	else {
		cout << -1 << endl;
	}
}