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