import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;
import std.range;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto nk = readNums!int;
  auto n = nk[0], k = nk[1];

  if(n - k < 2){
    writeln(-1);
    return;
  }

  auto m = k + 1 + iota(k+2, n).sum;
  writeln(m);

  foreach(i; 1 .. k+2){
    writeln(i, " ", i+1);
  }

  foreach(i; k+3 .. n+1){
    foreach(j; 1 .. i){
      writeln(j, " ", i);
    }
  }
}
