#include <bits/stdc++.h>
using namespace std;
int n, k, v[1000 + 10][1000 + 10];
int main(void) {
  cin >> n >> k;
  if (k > (n - 1) / 2) {
    cout << -1 << endl;
    return 0;
  }
  for (int a = 1; a <= n; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= n; c++) {
        if (a != c) {
          if (v[a][c] == 0) {
            v[a][c] = 1;
            v[c][a] = -1;
            break;
          }
        }
      }
    }
  }
  cout << n * k << endl;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (i != j && v[i][j] == 1) printf("%d %d\n", i, j);
    }
  return 0;
}
