#include <bits/stdc++.h>
using namespace std;
int has[3000][3000];
int main() {
  int n, m;
  cin >> n >> m;
  int maxi = ((n * (n - 1)) / 2) / n;
  if (m > maxi) {
    cout << "-1";
    return 0;
  } else {
    cout << n * m << endl;
    maxi = min(maxi, m);
    for (int i = 1; i <= n; i++) {
      int c = 0;
      for (int j = 1; j <= n; j++) {
        if (i != j && has[i][j] == 0 && has[j][i] == 0) {
          printf("%d %d\n", i, j);
          c++;
          has[i][j] = 1;
          has[j][i] = 1;
          if (c == maxi) break;
        }
      }
    }
  }
}
