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