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