#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int n, k;
int g[1005][1005];
void solve() {
  memset(g, 0, sizeof(g));
  if (2 * k > n - 1) {
    cout << -1 << endl;
    return;
  }
  cout << n * k << '\n';
  for (int i = 0; i < n; i++) {
    for (int j = (i + 1) % n, t = 0; t < k; t++, j = (j + 1) % n) {
      cout << i + 1 << ' ' << j + 1 << '\n';
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  while (cin >> n >> k) {
    solve();
  }
}
