void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.math;

  int n, d; rd(n, d);
  auto t=new long[](n);
  auto f=new long[](n);
  foreach(i; 0..n) rd(t[i], f[i]);

  long sm=0, pos=1, tm=0, m=0;
  foreach(i; 0..n){
    if(tm+(pos-1)+(f[i]-1)<=t[i]){
      sm+=m*(pos-1);
      m=1;
    }else if(tm+abs(pos-f[i])<=t[i] && m<d){
      // sm+=m*abs(pos-f[i]);
      sm+=m*abs(t[i]-tm);
      m++;
    }else{
      writeln(-1);
      return;
    }
    pos=f[i]; tm=t[i];
  }

  writeln(sm+m*(pos-1));
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}