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