#include <bits/stdc++.h>
using namespace std;
const int N = 1e3;
int g[N][N];
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  if (k > 3 || k == 1 || n == 4 && k == 2 || n <= 3) {
    cout << -1 << endl;
    return 0;
  }
  if (k == 2) {
    cout << n - 1 << endl;
    for (int(i) = (1); (i) < (n); (i)++) {
      cout << i << " " << i + 1 << endl;
    }
  } else {
    cout << 3 + n - 5 + 1 << endl;
    for (int(i) = (1); (i) < (4); (i)++) {
      cout << i << " " << i + 1 << endl;
    }
    for (int(i) = (5); (i) < (n + 1); (i)++) {
      cout << 2 << " " << i << endl;
    }
  }
  return 0;
}
