#include <bits/stdc++.h>
using namespace std;
int pp[1000][1000];
int main() {
  int n, k, i, j;
  while (cin >> n >> k) {
    memset(pp, 0, sizeof(pp));
    for (i = 1; i <= n; i++) pp[i][i] = 1;
    if (n * (n - 1) / 2 < k * n) {
      cout << -1 << endl;
      continue;
    }
    cout << n * k << endl;
    for (i = 1; i <= n; i++) {
      int kk = k;
      for (j = 1; j <= n && kk > 0; j++)
        if (pp[i][j] == 0) {
          printf("%d %d\n", i, j);
          pp[i][j] = pp[j][i] = 1;
          kk--;
        }
    }
  }
}
