#include <bits/stdc++.h>
using namespace std;
int N, K;
vector<pair<int, int> > out;
int main() {
  cin >> N >> K;
  int OK = K;
  for (int d = 1; d < N; ++d) {
    if (2 * d >= N) continue;
    if (K == 0) break;
    --K;
    for (int i = 0; i < N; ++i) out.push_back(make_pair(i, (i + d) % N));
  }
  if (((int)(out).size()) != OK * N)
    puts("-1");
  else {
    printf("%d\n", ((int)(out).size()));
    for (int i = 0; i < ((int)(out).size()); ++i)
      printf("%d %d\n", out[i].first + 1, out[i].second + 1);
  }
  return 0;
}
