#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  if (2 * k >= n)
    printf("-1\n");
  else {
    cout << n * k << endl;
    for (int i = 1; i <= n; ++i) {
      for (int j = i + 1; j <= i + k; ++j) {
        printf("%d %d\n", i, (j - 1) % n + 1);
      }
    }
  }
  return 0;
}
