#include <bits/stdc++.h>
using namespace std;
int adj[1001 + 7][1001 + 7], deg[1001 + 7], n, k;
int main(int argc, char **argv) {
  while (cin >> n >> k) {
    if (n * k > (n * (n - 1)) / 2) {
      cout << "-1\n";
      continue;
    }
    cout << n * k << "\n";
    memset(adj, 0, sizeof(adj));
    memset(deg, 0, sizeof(deg));
    for (int i = (int)1; i <= (int)n; i++) {
      for (int j = 1; j <= n && deg[i] < k; j++) {
        if (i == j) continue;
        if (adj[i][j] == 0) {
          cout << i << " " << j << "\n";
          deg[i]++;
          adj[j][i] = -1;
        }
      }
    }
  }
  return 0;
}
