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