#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long maxn = 1e3 + 10, inf = 4e18, mod = 1e9 + 7;
const long double pi = 3.14159265359, eps = 1e-9;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  if (k > 3 || k == 1 || k >= n)
    return cout << -1, 0;
  else if (k == 3) {
    cout << 2 * (n - 3) + 1 << endl;
    cout << "1 2" << endl;
    for (int i = 4; i <= n; i++) {
      cout << i << " 2" << endl;
      cout << i << " 3" << endl;
    }
  } else {
    if (n <= 4) return cout << -1, 0;
    cout << n - 1 << endl;
    for (int i = 1; i <= n - 1; i++) {
      cout << i << ' ' << i + 1 << endl;
    }
  }
  return 0;
}
