#include <bits/stdc++.h>
using namespace std;
long long C(long long a, long long b) {
  long long fz, fm, j;
  fz = 1;
  fm = 1;
  j = 1;
  for (long long i = a; i >= (a - b + 1); i--) {
    fz *= i;
    fm *= j;
    j++;
  }
  return fz / fm;
}
int main() {
  long long n, k;
  while (cin >> n >> k) {
    if (2 * k <= n - 1) {
      printf("%lld\n", n * k);
      for (long long i = 1; i <= n; i++) {
        for (long long j = 1; j <= k; j++) {
          if ((i + j) < (n + 1))
            printf("%lld %lld\n", i, (i + j) % (n + 1));
          else
            printf("%lld %lld\n", i, (i + j) % (n));
        }
      }
    } else {
      printf("-1\n");
    }
  }
  return 0;
}
