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