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