#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  if (n <= 3)
    cout << -1;
  else if (n == 4) {
    if (k == 3) {
      cout << "3\n1 2\n2 3\n3 4\n";
    } else
      cout << -1;
  } else {
    if (k == 2) {
      cout << n << endl;
      for (int i = (1); i <= (n - 1); i++) cout << i << ' ' << i + 1 << endl;
      cout << 1 << ' ' << n;
    } else if (k == 3) {
      cout << n - 1 << endl;
      cout << "2 3" << endl;
      cout << "1 3" << endl;
      for (int i = (4); i <= (n); i++) cout << 1 << ' ' << i << endl;
    } else {
      cout << -1;
    }
  }
}
