#include <bits/stdc++.h>
using namespace std;
int flag[1005][1005];
int main() {
  int i, j, m, n, k, ans, last;
  scanf("%d%d", &n, &k);
  if (k > (n - 1) / 2) {
    printf("-1\n");
    return 0;
  }
  ans = k * n;
  printf("%d\n", ans);
  for (i = 1; i <= n; i++) {
    last = i;
    for (j = 1; j <= k; j++) {
      last++;
      if (last > n) last = 1;
      printf("%d %d\n", i, last);
    }
  }
  return 0;
}
