#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3fffffff;
const int maxn = 100010;
int n, k;
int main() {
  cin >> n >> k;
  if (k > (n - 1) / 2)
    puts("-1");
  else {
    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);
  }
}
