#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  map<pair<int, int>, int> m, res;
  if (n < 2) {
    cout << -1;
    exit(0);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      int team = i + j;
      if (team > n) team %= n;
      if (m[make_pair(i, team)] || m[make_pair(team, i)] || team == i) {
        cout << -1;
        exit(0);
      }
      m[make_pair(i, team)] = 1;
      m[make_pair(team, i)] = 1;
      res[make_pair(i, team)] = 1;
    }
  }
  cout << res.size() << "\n";
  for (map<pair<int, int>, int>::iterator it = res.begin(); it != res.end();
       ++it)
    cout << it->first.first << " " << it->first.second << "\n";
  return 0;
}
