#include <bits/stdc++.h>
using namespace std;
struct SM {
  int u, v;
  SM(int a, int b) : u(a), v(b) {}
  SM() {}
};
int n, m;
vector<SM> a;
int main() {
  while (~scanf("%d %d", &n, &m)) {
    if (((2 * m) % n < m or m > n) and printf("-1\n")) continue;
    for (int i = 1; i <= n; i++)
      for (int k = i + 1; k <= m + i; k++)
        a.push_back(SM(i, ((k - 1) % n) + 1));
    printf("%d\n", a.size());
    for (int i = 0; i < a.size(); i++) printf("%d %d\n", a[i].u, a[i].v);
  }
  return 0;
}
