#include <bits/stdc++.h>
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  switch (k) {
    case 1:
      printf("-1\n");
      break;
    case 2:
      if (n < 5) {
        printf("-1\n");
        break;
      }
      printf("%d\n", n - 1);
      for (int i = 1; i < n; i++) printf("%d %d\n", i, i + 1);
      break;
    case 3:
      if (n < 4) {
        printf("-1\n");
        break;
      }
      printf("%d\n1 2\n2 3\n", n - 1);
      for (int i = 4; i <= n; i++) printf("3 %d\n", i);
      break;
    default:
      printf("-1\n");
      break;
  }
  return 0;
}
