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