#include <bits/stdc++.h>
using namespace std;
int v[1100][1100];
int main() {
  int n, k;
  cin >> n >> k;
  if (n > k + k) {
    cout << n * k << endl;
    for (int i = 1; i <= n; i++) {
      int t = k;
      for (int j = 1; j <= n; j++)
        if (i != j && !v[i][j] && !v[j][i] && t) {
          t--;
          v[i][j] = v[j][i] = 1;
          printf("%d %d\n", i, j);
        }
    }
  } else
    printf("-1\n");
}
