#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
  for (int i = 0; i < ((int)((t).size())); i++) s << t[i] << " ";
  return s;
}
int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
long long powmod(long long a, long long p, long long m) {
  long long r = 1;
  while (p) {
    if (p & 1) r = r * a % m;
    p >>= 1;
    a = a * a % m;
  }
  return r;
}
const int fx[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int main(int argc, char *argv[]) {
  int(n), (k);
  scanf("%d %d", &(n), &(k));
  ;
  if (k * n > (n - 1) * n / 2) {
    printf("-1\n");
  } else {
    printf("%d\n", n * k);
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= i + k; j++) {
        if (j <= n)
          printf("%d %d\n", i, j);
        else
          printf("%d %d\n", i, j - n);
      }
    }
  }
  return EXIT_SUCCESS;
}
