#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
void solv() {
  int n, k;
  scanf("%d%d", &n, &k);
  if (k > 3 || k == 1) {
    printf("-1\n");
    return;
  }
  vector<pair<int, int> > ans;
  if (k == 2) {
    if (n <= 4) {
      printf("-1\n");
      return;
    }
    for (int i = 1; i < n; ++i) ans.push_back(make_pair(i, i + 1));
  } else {
    if (n <= 3) {
      printf("-1\n");
      return;
    }
    ans.push_back(make_pair(1, 2));
    ans.push_back(make_pair(2, 3));
    ans.push_back(make_pair(3, 4));
    for (int i = 5; i <= n; ++i) {
      ans.push_back(make_pair(i, 3));
      ans.push_back(make_pair(i, 4));
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); ++i) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
}
int main() {
  solv();
  return 0;
}
