#include <bits/stdc++.h>
using namespace std;
int i, j, k, l, n, m, s, an, sum, tot, len, K, now, pp;
int main() {
  scanf("%d%d", &n, &m);
  if (n * m > n * (n - 1) / 2) {
    printf("-1\n");
    return 0;
  }
  printf("%d\n", n * m);
  for (int i = 1; i <= n; i++) {
    int j = i;
    for (int k = 1; k <= m; k++) {
      j = (j + 1) % n;
      if (!j) j = n;
      printf("%d %d\n", i, j);
    }
  }
  return 0;
}
