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