#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<int> > res(n, vector<int>(n, 0));
  bool flag = true;
  for (int i = 0; i < n; i++) {
    int kk = k;
    for (int j = 0; j < n; j++)
      if (kk && i != j && res[i][j] == 0) {
        kk--;
        res[i][j] = 1;
        res[j][i] = -1;
      }
    if (kk) flag = false;
  }
  if (flag) {
    cout << n * k << "\n";
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (res[i][j] == 1) cout << i + 1 << " " << j + 1 << "\n";
  } else
    cout << -1;
}
