#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  if (n == 2 && k == 1) {
    cout << -1;
    return 0;
  }
  if (2 * k < n) {
    cout << n * k << endl;
    for (int g = 1; g <= n; g++) {
      for (int y = g + 1; y < g + k + 1; y++) {
        cout << g << " ";
        if (y <= n) {
          cout << y << endl;
        } else {
          cout << (y % n) << endl;
        }
      }
    }
  } else {
    cout << -1;
    return 0;
  }
}
