#include <bits/stdc++.h>
using namespace std;
int main() {
  cout.tie(0), cin.tie(0);
  int i, j, k, n, comb, a[1001], count = 0;
  cin >> n >> k;
  comb = (n * (n - 1)) / 2;
  int z = comb / n;
  if ((k < n / 2 && n % 2 == 0) || (k <= n / 2 && n % 2 == 1)) {
    cout << n * k << endl;
    for (i = 1; i < n + 1; i++) {
      for (j = i + 1; j < i + k + 1; j++) {
        if (i <= n)
          cout << i << " ";
        else
          cout << i - n << " ";
        if (j <= n)
          cout << j << "\n";
        else
          cout << j - n << "\n";
      }
    }
  } else {
    cout << "-1";
    return 0;
  }
  return 0;
}
