#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > e;
bool o[1002][1002];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int x = (1); x < (k + 1); x++)
    for (int i = (0); i < (n); i++) {
      int j = (i + x) % n;
      if (o[i][j] || i == j) {
        cout << -1 << endl;
        return 0;
      }
      o[i][j] = o[j][i] = 1;
      e.push_back(pair<int, int>(i + 1, j + 1));
    }
  printf("%d\n", e.size());
  for (int i = (0); i < (e.size()); i++)
    printf("%d %d\n", e[i].first, e[i].second);
}
