#include <bits/stdc++.h>
using namespace std;
int g[1111][1111], n, k;
int main() {
  cin >> n >> k;
  int ans = k * n * 2;
  vector<int> a, b;
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 1; j <= n; j++) {
      if (i != j && g[i][j] == 0) {
        g[i][j] = 1;
        g[j][i] = -1;
        a.push_back(i);
        b.push_back(j);
        cnt++;
        if (cnt == k) break;
      }
    }
  }
  int cnt = (int)(a.size());
  if (cnt != ans / 2)
    cout << -1 << endl;
  else {
    cout << cnt << endl;
    for (int i = 0; i < cnt; i++) printf("%d %d\n", a[i], b[i]);
  }
  return 0;
}
