#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, a, b, c, d, i, j, k, l, n, m, x, y;
  scanf("%lld %lld", &n, &k);
  a = (n * (n - 1)) / 2;
  b = a / n;
  if (k > b)
    printf("-1");
  else {
    printf("%lld\n", k * n);
    b = a / n;
    l = 1;
    j = 1;
    d = 1;
    c = n;
    while (c--) {
      d++;
      if (d > n) d = 1;
      j = d;
      if (j > n) j = 1;
      for (i = 0; i < k; i++) {
        printf("%lld %lld\n", l, j);
        j++;
        if (j > n) j = 1;
      }
      l++;
    }
  }
}
