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