#include <bits/stdc++.h>
using namespace std;
int arr[1010][1010] = {{0}};
int main() {
  int n, k;
  scanf("%d", &n);
  scanf("%d", &k);
  if (n * k > (n * (n - 1)) / 2) {
    printf("-1\n");
    return 0;
  }
  int ct[1010] = {0}, ct2[1010] = {0};
  printf("%d\n", n * k);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      if (ct[i] == k) break;
      if (arr[i][j] == 0) {
        printf("%d %d\n", i, j);
        arr[i][j] = 1;
        arr[j][i] = 1;
        ct[i]++;
      }
    }
  }
  return 0;
}
