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