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