#include <bits/stdc++.h>
using namespace std;
long long n, k, t;
char ch;
string s;
int main() {
  cin >> n >> k;
  if (k > (n - 1) / 2) {
    cout << -1 << endl;
    return 0;
  }
  cout << n * k << endl;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= k; j++) printf("%d %d\n", i, (i + j - 1) % n + 1);
}
