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