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