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