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