#include <bits/stdc++.h>
using namespace std;
int n, k;
inline void ReadInput(void) {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
}
inline void Refresh(void) {}
inline void solve(void) {
  int m1 = n * (n - 1);
  m1 /= 2;
  if (m1 >= n * k) {
    printf("%d\n", n * k);
    for (int i = 1; i <= n; i++) {
      int j = i;
      for (int count = 1; count <= k; count++) {
        if ((j + count) == n)
          printf("%d %d\n", j, n);
        else
          printf("%d %d\n", j, (j + count) % n);
      }
    }
  } else
    cout << "-1\n";
}
int main(int argc, const char* argv[]) {
  ReadInput();
  solve();
  return 0;
}
