#include <bits/stdc++.h>
using namespace std;
int g[1005][1005], d[1005];
bool solve(int n, int k) {
  for (int i = 1; i <= n; ++i) {
    int j = 0;
    while (j < n && d[i] != k) {
      ++j;
      if (j == i || g[j][i]) continue;
      g[i][j] = 1;
      ++d[i];
    }
    if (d[i] != k) return 0;
  }
  printf("%d\n", n * k);
  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 1;
}
int main() {
  int n, k;
  cin >> n >> k;
  if (!solve(n, k)) puts("-1");
  return 0;
}
