#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, m;
int main() {
  int t, x, y, z, ca = 1;
  scanf("%d%d", &(n), &(m));
  if (m >= (n + 1) / 2)
    printf("%d\n", (-1));
  else {
    printf("%d\n", (n * m));
    for (int i = 0; i < (int)(n); ++i) {
      for (int j = (int)(1); j <= (int)(m); ++j)
        printf("%d %d\n", i + 1, (i + j) % n + 1);
    }
  }
  return 0;
}
