#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (((n - 1)) / 2 < m)
    cout << "-1";
  else {
    cout << m * n << endl;
    for (int i = 1; i <= n; i++) {
      int k = i + 1;
      long long int c = 0;
      while (c < m) {
        if (k > n) {
          k = 1;
        }
        printf("%d %d\n", i, k);
        k++;
        c++;
      }
    }
  }
}
