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(3 * (n - 2) / 2 < k){
    writeln(-1);
    return;
  }

  if(n - k >= 2){
     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);
       }
     }
  } else {
    writeln(k+1);

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

    for(int i = 1; i < 2 * (k - n + 2); i += 2){
      writeln(i, " ", n);
    }
  }
}
