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