#include <bits/stdc++.h>
using namespace std;
template <class T>
string tostring(T x) {
  ostringstream out;
  out << x;
  return out.str();
}
long long toint(string s) {
  istringstream in(s);
  long long x;
  in >> x;
  return x;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int s = 0;
  for (int i = 1; i <= n - 1; i++) s += i;
  int d = s / n;
  if (d < k) {
    printf("-1\n");
    return 0;
  }
  cout << k * n << endl;
  for (int i = 1; i <= n; i++) {
    int t = i;
    for (int j = 0; j < k; j++) {
      t++;
      if (t % n == 0)
        printf("%d %d\n", i, n);
      else
        printf("%d %d\n", i, t % n);
    }
  }
  return 0;
}
