#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int n, k;
  cin >> n >> k;
  if (n * (n - 1) / 2 < n * k)
    cout << -1;
  else {
    cout << n * k << "\n";
    for (int i = 0; i < n; i++) {
      int j = 1;
      while (j <= k) {
        cout << i + 1 << " " << (i + j) % n + 1 << "\n";
        j++;
      }
    }
  }
  return 0;
}
