#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int G[1020][1020] = {0};
int deg[1020] = {0};
int main() {
  int n, k, m = 0;
  bool can = true;
  scanf("%d%d", &n, &k);
  for (int(i) = (1); (i) <= (n); ++(i)) {
    for (int(j) = (1); (j) <= (n); ++(j))
      if (i != j && !G[i][j] && !G[j][i] && deg[i] < k)
        deg[i]++, m++, G[i][j] = 1;
    if (deg[i] != k) {
      can = false;
      break;
    }
  }
  if (!can)
    puts("-1");
  else {
    printf("%d\n", m);
    for (int(i) = (1); (i) <= (n); ++(i)) {
      for (int(j) = (1); (j) <= (n); ++(j))
        if (G[i][j]) printf("%d %d\n", i, j);
    }
  }
  return 0;
}
