#include <bits/stdc++.h>
using namespace std;
int n, k, r, tk[1005][1005], ct[1005];
vector<pair<int, int> > v;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      ct[i]++;
      if (ct[i] == i) ct[i]++;
      if (tk[i][ct[i]] == 1 || tk[ct[i]][i] == 1) {
        while (tk[i][ct[i]] == 1 || tk[ct[i]][i] == 1) {
          ct[i]++;
          if (i == ct[i]) ct[i]++;
        }
      }
      if (ct[i] > n) {
        cout << -1;
        return 0;
      }
      v.push_back(make_pair(i, ct[i]));
      tk[i][ct[i]] = 1;
      tk[ct[i]][i] = 1;
    }
  }
  cout << n * k << endl;
  for (int i = 0; i < v.size(); i++) {
    printf("%d %d\n", v[i].first, v[i].second);
  }
  return 0;
}
