#include <bits/stdc++.h>
using namespace std;
int n, k, a[1003][1003], Count[1003];
int main() {
  scanf("%d%d", &n, &k);
  for (int j = 1; j <= k; j++)
    for (int i = 0; i < n; i++) {
      a[i][(i + j) % n] = 1;
      a[(i + j) % n][i] = -1;
    }
  for (int i = 0; i < n; i++) a[i][i] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (a[i][j] == 1) Count[i]++;
  for (int i = 0; i < n; i++)
    if (Count[i] != k) {
      cout << -1 << endl;
      return 0;
    }
  cout << n * k << endl;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (a[i][j] == 1) printf("%d %d\n", i + 1, j + 1);
}
