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