#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
bool pl[1009][1009];
int n, k;
int main() {
  scanf("%d%d", &n, &k);
  vector<pair<int, int> > v;
  for (int i = 0; i < (int)(n); i++) {
    int cc = 0;
    pl[i][i] = 1;
    for (int j = 0; j < (int)(n); j++)
      if (!pl[i][j]) {
        v.push_back(make_pair(i + 1, j + 1));
        pl[i][j] = pl[j][i] = 1;
        cc++;
        if (cc == k) break;
      }
    if (cc < k) {
      cout << -1 << endl;
      return 0;
    }
  }
  printf("%d\n", ((int)v.size()));
  for (int i = 0; i < (int)(((int)v.size())); i++)
    printf("%d %d\n", v[i].first, v[i].second);
  return 0;
}
