#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<pair<int, int> > ans;
bool isCorrect = true;
int main() {
  cin >> n >> k;
  if (n - k - 1 < k) {
    cout << -1;
    return 0;
  }
  cout << n * k << "\n";
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < k; j++) {
      cout << i << " " << (i + j) % n + 1 << "\n";
    }
  return 0;
}
