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