#include <bits/stdc++.h>
using namespace std;
int M[2000][2000];
int main() {
  vector<pair<int, int> > V;
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 1; j <= n; j++) {
      if (i != j && !M[i][j] && cnt < k) {
        V.push_back(make_pair(i, (j)));
        cnt++;
        M[i][j]++;
        M[j][i]++;
      }
    }
    if (cnt != k) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << V.size() << endl;
  for (int i = 0; i < V.size(); i++) printf("%d %d\n", V[i].first, V[i].second);
  return 0;
}
