#include <bits/stdc++.h>
using namespace std;
int a[40005];
int main() {
  int i, j;
  int n, m, x;
  while (scanf("%d %d", &n, &m) != EOF) {
    if ((n == 1 || n == 2) && m == 1) {
      printf("-1\n");
      continue;
    }
    if (n < (2 * m + 1)) {
      if (m == 1) {
        printf("%d\n", n * m);
        for (i = 1; i <= n; i++) {
          for (j = 1; j <= m; j++) {
            x = i + j;
            if (x > n) {
              x = x - n;
            }
            printf("%d %d\n", i, x);
          }
        }
      } else
        printf("-1\n");
      continue;
    }
    printf("%d\n", n * m);
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= m; j++) {
        x = i + j;
        if (x > n) {
          x = x - n;
        }
        printf("%d %d\n", i, x);
      }
    }
  }
  return 0;
}
