#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[1000][1000];
int i, j;
int main() {
  scanf("%d %d", &n, &k);
  for (i = 0; i < n; i++) a[i][i] = -1;
  int m = 0;
  for (i = 0; i < n; i++) {
    int c = 0;
    for (j = 0; j < n; j++) {
      if (a[i][j] == -1) continue;
      a[i][j] = 1;
      a[j][i] = -1;
      c++;
      m++;
      if (c == k) break;
    }
    if (c != k) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", m);
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      if (a[i][j] == 1) printf("%d %d\n", i + 1, j + 1);
  return 0;
}
