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