#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
void fmain(int tid) {
  scanf("%d%d", &n, &k);
  if (k == 1 || k >= 4) et();
  if (k == 2) {
    if (n < 5) et();
    printf("%d\n", n - 1);
    for (int(i) = 1; (i) <= (int)(n - 1); (i)++) printf("%d %d\n", i, i + 1);
  } else {
    if (n < 4) et();
    printf("%d\n", n - 1);
    puts("1 2");
    puts("2 3");
    for (int i = 4; i <= n; i++) {
      printf("%d %d\n", 3, i);
    }
  }
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
