#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  if (n <= 3) {
    cout << -1 << endl;
    return 0;
  }
  int i;
  if (k == 2) {
    if (n == 4) {
      cout << -1 << endl;
      return 0;
    }
    cout << n - 1 << endl;
    for (i = 1; i <= n - 1; i++) {
      cout << i << " " << i + 1 << endl;
    }
  } else if (k == 3) {
    cout << n - 1 << endl;
    for (i = 1; i <= 3; i++) cout << i << " " << i + 1 << endl;
    i++;
    for (; i <= n; i++) cout << i << " " << 2 << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
