#include <bits/stdc++.h>
using namespace std;
bool aPlayed[1000][1000];
vector<vector<int> > aBeat;
int main() {
  int N, K;
  int i, j;
  vector<int> v;
  cin >> N >> K;
  if (2 * K > (N - 1)) {
    cout << -1 << endl;
    return 0;
  }
  for (i = 0; i < N; i++) aBeat.push_back(v);
  for (i = 0; i < N; i++) {
    for (j = 0; j < K; j++) {
      int other = i + 1 + j;
      if (other >= N) other -= N;
      if (aPlayed[other][i]) {
        cout << -1 << endl;
        return 0;
      }
      aBeat[i].push_back(other);
      aPlayed[i][other] = 1;
      aPlayed[other][i] = 1;
    }
  }
  int nMatches = 0;
  for (i = 0; i < N; i++) nMatches += aBeat[i].size();
  cout << nMatches << endl;
  for (i = 0; i < N; i++) {
    for (j = 0; j < aBeat[i].size(); j++) {
      printf("%d %d\n", i + 1, aBeat[i][j] + 1);
    }
  }
}
