#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > ans;
int main() {
  int n, k, i;
  scanf("%d %d", &n, &k);
  if ((k > 3) || (n <= 3) || (k == 1)) {
    puts("-1");
    return 0;
  }
  if (k == 2) {
    if (n == 4) {
      puts("-1");
      return 0;
    }
    for (i = 1; i <= n - 1; i++) {
      ans.push_back(make_pair(i, i + 1));
    }
  } else {
    ans.push_back(make_pair(1, 2));
    ans.push_back(make_pair(1, 3));
    for (i = 4; i <= n; i++) {
      ans.push_back(make_pair(i, 2));
    }
  }
  printf("%d\n", (int(ans.size())));
  for (i = 0; i < (int(ans.size())); i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
