#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  if (n <= 3 || (k != 3 and k != 2)) {
    printf("-1\n");
    return 0;
  }
  if (k == 2) {
    if (n == 4) {
      printf("-1\n");
      return 0;
    }
    printf("%d\n", n - 1);
    for (int i = 1; i < n; i++) {
      printf("%d %d\n", i, i + 1);
    }
  } else {
    vector<string> resp;
    resp.emplace_back("1 2");
    resp.emplace_back("2 3");
    resp.emplace_back("3 4");
    for (int i = 5; i <= n; i++) {
      string aux = "1 ";
      aux += to_string(i);
      resp.emplace_back(aux);
      aux = "3 ";
      aux += to_string(i);
      resp.emplace_back(aux);
    }
    printf("%d\n", (int)resp.size());
    for (auto x : resp) {
      printf("%s\n", x.c_str());
    }
  }
  return 0;
}
