#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, k;
  cin >> n >> k;
  if (n <= 2 * k)
    cout << -1;
  else {
    cout << n * k << "\n";
    for (long i = 1; i <= n; i++) {
      for (long j = i + 1; j <= i + k; j++) {
        if (j <= n)
          cout << i << " " << j << "\n";
        else
          cout << i << " " << j % n << "\n";
      }
    }
  }
}
