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