#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, k, a, b, vis[N];
void fail() {
  cout << -1 << endl;
  exit(0);
}
int main() {
  cin >> n >> k;
  if (n * k > n * (n - 1) / 2) fail();
  int m = n * k;
  printf("%d\n", m);
  for (int i = 1; i <= n && m; i++)
    for (int j = i + 1; j <= n && m; j++) {
      if (vis[i] != k) {
        a = i;
        b = j;
        vis[i]++;
      } else if (vis[j] != k) {
        a = j;
        b = i;
        vis[j]++;
      } else
        continue;
      printf("%d %d\n", a, b);
    }
  return 0;
}
