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