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