#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, k, p = 2;
  cin >> n >> k;
  int c = ceil((double)n / 2);
  if (k >= c) {
    cout << "-1"
         << "\n";
    return 0;
  }
  cout << n * k << "\n";
  for (int i = 1; i < n + 1; i++) {
    c = i + 1;
    for (int j = 1; j < k + 1; j++) {
      if (c > n) c = 1;
      cout << i << " " << c << "\n";
      c++;
    }
  }
}
