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