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