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