const main = (inputs) => {
  var N = inputs[0].split(" ")[0]-0;
  var K = inputs[0].split(" ")[1]-0;
  var list = makeList(N);
  if(K > list.length-N+1){
    console.log(-1);
  }else{
    for(var i=0;i<K;i++){
      var tmp = list.shift();
      if(tmp.b == N){
        list.push(tmp);
        i--;
      }
    }
    console.log(list.length);
    for(var i=0;i<list.length;i++){
      console.log(list[i].a + " " + list[i].b);
    }
  }
}

function makeList(n){
  var list = [];
  for(var i=1;i<=n;i++){
    for(var j=i+1;j<=n;j++){
      list.push({a:i, b:j});
    }
  }
  return list;
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));
