#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<vector<bool> > V;
  V.resize(n, vector<bool>(n, 0));
  vector<pair<int, int> > P;
  for (int i = 0; i < n; i++) {
    int t = 0;
    for (int q = 0; q < n; q++) {
      int j = i + q;
      j %= n;
      if (i != j && !V[i][j]) {
        V[i][j] = V[j][i] = 1;
        P.push_back(make_pair(i, j));
        t++;
      }
      if (t == k) break;
    }
    if (t < k) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << (int)P.size() << endl;
  for (int i = 0; i < (int)P.size(); i++)
    cout << P[i].first + 1 << " " << P[i].second + 1 << endl;
  return 0;
}
