#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  while (scanf("%d%d", &n, &k) != -1) {
    int i, j, f = 1;
    int map[1203][1201];
    memset(map, 0, sizeof(map));
    for (i = 1; i <= n; i++) {
      int x = k;
      for (j = i + 1;; j++) {
        if (j == n + 1) j = 1;
        if (j == i) break;
        if (!map[j][i]) {
          map[i][j] = 1;
          x--;
          if (x == 0) break;
        }
      }
      if (x != 0) {
        f = 0;
        break;
      }
    }
    if (f) {
      printf("%d\n", n * k);
      for (i = 1; i <= n; i++) {
        for (j = 1; j <= n; j++) {
          if (map[i][j]) printf("%d %d\n", i, j);
        }
      }
    } else
      printf("-1\n");
  }
}
