#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const double eps = 1e-9;
const int INF = inf;
const double EPS = eps;
struct __timestamper {};
int main() {
  int n, k;
  while (scanf("%d%d", &n, &k) == 2) {
    if (n * k > n * (n - 1) / 2) {
      printf("-1\n");
      continue;
    }
    printf("%d\n", n * k);
    for (int i = 0; i < n; i++) {
      for (int i2 = 1; i2 <= k; i2++)
        printf("%d %d\n", i + 1, (i + i2) % n + 1);
    }
  }
  return 0;
}
