#include <bits/stdc++.h>
const bool debug = false;
using namespace std;
long long powmod(long long a, long long b, long long MOD) {
  long long res = 1;
  a %= MOD;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
void buginfo(const char* f, ...) {
  if (!debug) return;
  va_list al;
  va_start(al, f);
  vprintf(f, al);
  va_end(al);
}
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  if (m > 3 || m < 2 || n < 4 || (n == 4 && m == 2)) {
    printf("-1\n");
    return 0;
  }
  if (m == 2) {
    printf("%d\n", n);
    for (int i = 1; i < n + 1; ++i) printf("%d %d\n", i, i == n ? 1 : i + 1);
  } else {
    printf("%d \n", 3 + (n - 4) * 2);
    printf("1 2\n");
    printf("2 3\n");
    printf("3 4\n");
    for (int i = 5; i < n + 1; ++i) printf("2 %d\n3 %d\n", i, i);
  }
}
