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