#include <bits/stdc++.h>
using namespace std;
const int N = 111111;
const int INF = 1000000000, mod = 1000000007;
const long long LLINF = 1000000000000000000ll;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  if (n * k > n * (n - 1) / 2) return puts("-1"), 0;
  printf("%d\n", n * k);
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= k; ++j) {
      printf("%d %d\n", i + 1, (i + j) % n + 1);
    }
  }
  return 0;
}
