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