#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:16777216")
#pragma warning(disable : 4786)
int main() {
  ios_base::sync_with_stdio(0);
  int n, k, i, m, x, y;
  while (cin >> n >> k) {
    x = (n - 1) / 2;
    if (k > x) {
      cout << -1 << endl;
      continue;
    }
    cout << n * k << endl;
    x = 1;
    while (k--) {
      for (i = 1; i <= n; i++) {
        y = (i + x - 1) % n + 1;
        printf("%d %d\n", i, y);
      }
      x++;
    }
  }
  return 0;
}
