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