#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)2e5 + 7;
const int INF = (int)1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-9;
const int base = 1000 * 1000 * 1000;
int n, m, k;
long long a[maxn];
int kol;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  scanf("%d%d", &n, &k);
  if (k * n > ((n * (n - 1)) / 2)) {
    printf("-1\n");
    return 0;
  }
  printf("%d\n", k * n);
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j < k + i; ++j) {
      printf("%d %d\n", i, (j % n) + 1);
    }
  }
  return 0;
}
