#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int n, k, m;
int a[1010][1010];
void Run() {
  cin >> n >> k;
  if ((n - k - 1) * n < n * k) {
    cout << -1;
    return;
  }
  cout << n * k << endl;
  for (int i = 1; i <= n; i++) {
    int c = 0;
    for (int j = 1; j <= n; j++) {
      if (i != j && a[i][j] != -1) {
        printf("%d %d\n", i, j);
        c++;
        a[i][j] = a[j][i] = -1;
      }
      if (c == k) break;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  Run();
  return 0;
}
