#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
bool win[N][N];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    int cnt = 0;
    for (int j = 0; j < n && cnt < k; ++j)
      if (i != j && !win[j][i]) win[i][j] = true, ++cnt;
    if (cnt != k) return cout << -1, 0;
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (win[i][j]) ++cnt;
  printf("%d\n", cnt);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (win[i][j]) printf("%d %d\n", i + 1, j + 1);
  return 0;
}
