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