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