#include <bits/stdc++.h>
using namespace std;
bool usd[1009][1009];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i)
    for (int d = 1; d <= k; ++d) {
      int v = (i + d) % n;
      if (v == i) {
        cout << -1 << endl;
        return 0;
      }
      if (!usd[v][i] && !usd[i][v]) {
        usd[i][v] = true;
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  cout << n * k << endl;
  for (int i = 0; i < n; ++i)
    for (int d = 1; d <= k; ++d) {
      int v = (i + d) % n;
      cout << i + 1 << ' ' << v + 1 << '\n';
    }
  cout << endl;
}
