#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
void mysol() {
  set<pair<long long, long long>> s;
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    long long l = i;
    long long r = k;
    long long cnt = 0;
    while (cnt < n and r) {
      if ((i + cnt) % n + 1 != i)
        if (s.find({(i + cnt) % n + 1, i}) == s.end()) {
          s.insert({i, (i + cnt) % n + 1});
          r--;
        }
      cnt++;
    }
  }
  if (s.size() < n * k) {
    cout << -1;
    return;
  }
  cout << n * k << '\n';
  for (auto a : s) cout << a.first << ' ' << a.second << '\n';
}
int32_t main() {
  fast();
  { mysol(); }
  return 0;
}
