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