#include <bits/stdc++.h>
using namespace std;
int n, k;
int ans;
int main(int argc, const char* argv[]) {
  cin >> n >> k;
  if (k > 3 || k == 1) {
    cout << "-1" << endl;
    return 0;
  }
  if (k == 2) {
    if (n <= 4) {
      cout << "-1" << endl;
      return 0;
    } else {
      cout << n - 1 << endl;
      for (int i = 1; i <= n - 1; i++) {
        cout << i << " " << i + 1 << endl;
      }
    }
  } else {
    if (n < 4) {
      cout << "-1" << endl;
      return 0;
    } else {
      ans = 3 + max(0, n - 4) * 2;
      cout << ans << endl;
      cout << "1 2" << endl;
      cout << "2 3" << endl;
      cout << "3 4" << endl;
      for (int i = 5; i <= n; i++) {
        cout << i << " 1" << endl;
        cout << i << " 3" << endl;
      }
    }
  }
  return 0;
}
