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