#include <bits/stdc++.h>
using namespace std;
struct Answer {
  int a, b;
} ans[1001000];
bool vis[1010][1010];
int n, k;
int main() {
  cin >> n >> k;
  if (n <= k) {
    cout << -1 << endl;
    return 0;
  }
  bool ok = true;
  int num = 0;
  for (int i = 1; i <= n; i++) {
    int T = k, tail = i;
    vis[i][i] = true;
    while (T--) {
      tail++;
      if (tail > n) tail = 1;
      if (vis[i][tail] || vis[tail][i]) {
        ok = false;
        break;
      }
      num++;
      ans[num].a = i;
      ans[num].b = tail;
      vis[i][tail] = vis[tail][i] = true;
    }
  }
  if (!ok)
    cout << -1 << endl;
  else {
    cout << n * k << endl;
    for (int i = 1; i <= n * k; i++) {
      printf("%d %d\n", ans[i].a, ans[i].b);
    }
  }
}
