#include <bits/stdc++.h>
using namespace std;
long long int a[1001][1001];
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int tot_edge = n * (n - 1);
  tot_edge /= 2;
  if (tot_edge < n * k) {
    cout << -1;
    return 0;
  }
  long long int num = 0;
  long long int temp = 0;
  for (int i = 1; i <= n; i++) {
    temp = k;
    for (int j = 1; j <= n; j++) {
      if (j == i) continue;
      if (a[j][i] == 0) {
        a[i][j] = 1;
        num++;
        temp--;
      }
      if (temp == 0) break;
    }
    if (temp != 0) {
      cout << -1;
      return 0;
    }
  }
  cout << num << "\n";
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j]) cout << i << " " << j << "\n";
    }
  }
}
