#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (n * (n - 1) / 2 < n * m) {
    cout << -1 << endl;
    return 0;
  }
  cout << n * m << '\n';
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x;
      x = i + j;
      if (x > n) x %= n;
      cout << i << " " << x << '\n';
    }
  }
  return 0;
}
