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