#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60000000")
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = 3.1415926535897932384626433832795;
const string task = "";
template <class T>
T sqr(T x) {
  return x * x;
}
int n, k;
int main() {
  scanf("%d%d", &n, &k);
  if (n <= 3 || k == 1 || k > 3) {
    printf("-1\n");
    return 0;
  }
  if (n == 4 && k == 2) {
    printf("-1\n");
    return 0;
  }
  if (k == 2) {
    printf("%d\n", n - 1);
    for (int i = 1; i < n; i++) {
      printf("%d %d\n", i, i + 1);
    }
    return 0;
  }
  printf("%d\n", 2 * (n - 3) + 1);
  printf("1 2\n");
  for (int i = 3; i <= n - 1; i++) {
    printf("%d %d\n%d %d\n", i, 2, i, n);
  }
  return 0;
}
