#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, k;
  cin >> n >> k;
  long long int game = (n * (n + 1)) / 2 - n;
  if (n * k <= game) {
    cout << n * k << "\n";
    for (long long int i = 1; i <= n; i++) {
      for (long long int j = i + 1; j <= i + k; j++) {
        long long int g = j % n == 0 ? j : j % n;
        cout << i << " " << g << "\n";
      }
    }
  } else {
    cout << -1;
  }
}
