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