#include <bits/stdc++.h>
using namespace std;
const double eps = 1.0e-11;
const double pi = acos(-1.0);
int main() {
  int n, k;
  cin >> n >> k;
  if ((n - 1) / 2 < k) {
    cout << "-1\n";
    return 0;
  }
  vector<pair<int, int> > res;
  for (long long i = 0; i < n; i++) {
    for (long long j = 1; j <= k; j++) res.push_back(make_pair(i, (i + j) % n));
  }
  cout << (int)(res).size() << endl;
  for (long long i = 0; i < (int)(res).size(); i++)
    cout << res[i].first + 1 << " " << res[i].second + 1 << "\n";
  return 0;
}
