#include <bits/stdc++.h>
using namespace std;
enum { BLACK = -1, RED, WHITE };
int main() {
  int n, k;
  cin >> n >> k;
  if (n >= 2 * k + 1) {
    int a[1001][1001] = {};
    cout << n * k << endl;
    for (int i = 0; i < n; i++) {
      int games = 0;
      for (int j = 0; j < n && games < k; j++) {
        if (i == j) a[i][j] = BLACK;
        if (a[i][j] == RED) {
          a[i][j] = WHITE;
          printf("%d %d\n", i + 1, j + 1);
          a[j][i] = BLACK;
          games++;
        }
      }
    }
  } else
    cout << -1 << endl;
  return 0;
}
