#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  if (n * k * 2 > n * (n - 1)) {
    cout << "-1\n";
    return 0;
  }
  cout << n * k << endl;
  vector<vector<int>> v(n);
  for (auto& vv : v) vv.resize(n);
  for (int i = 0; i < n; ++i) {
    int left_k = k;
    for (int j = 0; j < n; ++j) {
      if (i != j && v[i][j] == 0) {
        v[i][j] = 1;
        v[j][i] = -1;
        cout << i + 1 << ' ' << j + 1 << '\n';
        if (--left_k == 0) break;
      }
    }
  }
}
