#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
int main() {
  int n, k, i, j;
  scanf("%d%d", &n, &k);
  if (n <= 3 || k == 1 || k > 3)
    printf("-1\n");
  else if (n == 4 && k == 2)
    printf("-1\n");
  else if (k == 2) {
    printf("%d\n", n - 1);
    for (i = 0; i < n - 1; printf("%d %d\n", i + 1, i + 2), i++)
      ;
  } else if (k == 3) {
    printf("%d\n", (n - 3) * (n - 4) / 2 + n - 3 + 2);
    for (i = 0; i < n - 3; i++)
      for (j = 0; j < i; printf("%d %d\n", i + 1, j + 1), j++)
        ;
    for (i = 0; i < n - 3; printf("%d %d\n", i + 1, n - 2), i++)
      ;
    printf("%d %d\n", n - 2, n - 1);
    printf("%d %d\n", n - 1, n);
  }
  return 0;
}
