#include <bits/stdc++.h>
struct an {
  int st, end;
};
int mat[1009][1009];
int main() {
  int n, k, i, j, c = 0, it, flag = 0;
  struct an ans[1000009];
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; i++) {
    it = 0;
    for (j = 1; j <= n; j++) {
      if (mat[i][j] == 1 || j == i)
        continue;
      else {
        ans[c].st = i;
        ans[c].end = j;
        c++;
        it++;
        mat[i][j] = 1;
        mat[j][i] = 1;
      }
      if (it >= k) break;
    }
    if (it < k) {
      flag = 1;
      break;
    }
  }
  if (flag == 1)
    printf("-1\n");
  else {
    printf("%d\n", c);
    for (k = 0; k < c; k++) printf("%d %d\n", ans[k].st, ans[k].end);
  }
  return 0;
}
