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