#include <bits/stdc++.h>
using namespace std;
vector<int> x, y;
bool p[1005][1005];
int need[1005];
int n, k;
int main() {
  cin >> n >> k;
  if (n - 1 < 2 * k) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < k; i++)
    for (int v = 0; v < n; v++) p[v][(v + i + 1) % n] = 1;
  for (int i = 0; i < n; i++) {
    int win = 0;
    for (int j = 0; j < n; j++)
      if (p[i][j]) win++;
    if (win != k) {
      cout << "OOOps";
      return 0;
    }
    for (int j = 0; j < n; j++)
      if (p[i][j] && p[j][i]) {
        cout << "OOps";
        return 0;
      }
  }
  printf("%d\n", n * k);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (p[i][j]) printf("%d %d\n", i + 1, j + 1);
}
