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