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