#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, k, c, s, ss, f, a[2000000], b[2000000], d[2000][2000];
int main() {
  scanf("%d", &n);
  scanf("%d", &k);
  if (n == 1) {
    cout << -1;
    return 0;
  }
  s = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= k; j++) {
      c = i + j;
      if (c > n) c %= n;
      if (d[i][c] == 1 || i == c) {
        cout << -1;
        return 0;
      }
      d[i][c] = 1;
      d[c][i] = 1;
      s++;
      a[s] = i;
      b[s] = c;
    }
  cout << s << endl;
  for (i = 1; i <= s; i++) {
    printf("%d ", a[i]);
    printf("%d\n", b[i]);
  }
  return 0;
}
