#include <bits/stdc++.h>
using namespace std;
int a[1005][1005], i, m, ans, k, l, j, q, x, n, ma, mi;
string s;
int main() {
  cin >> n >> k;
  if (k >= (n + 1) / 2) {
    cout << -1;
    return 0;
  }
  cout << n * k << endl;
  for (int i = 1; i <= n; i++) {
    int w = k;
    for (int j = 1; j <= n; j++) {
      if (a[i][j] == 1 || i == j) continue;
      cout << i << " " << j << endl;
      a[i][j] = 1;
      a[j][i] = 1;
      w--;
      if (!w) break;
    }
  }
}
