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