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