#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  long long int x = n - 2 * k;
  if (x < 1) {
    cout << "-1";
    return 0;
  }
  cout << n * k << '\n';
  for (long long int i = 1; i <= n - k; i++) {
    x = k;
    long long int it = i + 1;
    while (x--) {
      cout << i << " " << it << '\n';
      it++;
    }
  }
  long long int it = 1;
  for (long long int i = n - k + 1; i <= n; i++) {
    for (long long int j = i + 1; j <= n; j++) {
      cout << i << " " << j << '\n';
    }
    for (long long int j = 1; j <= it; j++) {
      cout << i << " " << j << '\n';
    }
    it++;
  }
  return 0;
}
