#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double PI = acos(-1.0);
using namespace std;
int lose[1005];
int vis[1005][1005];
int main(void) {
  int n, k;
  scanf("%d %d", &n, &k);
  if (n * (n - 1) / 2 < n * k) {
    puts("-1");
    return 0;
  }
  vector<pair<int, int> > ans;
  for (int i = 0; i < n; i++) {
    int now = (i + 1) % n;
    for (int j = 0; j < k; j++) {
      ans.push_back(make_pair(i, now));
      now = (now + 1) % n;
    }
  }
  int m = ans.size();
  printf("%d\n", m);
  for (int i = 0; i < m; i++) {
    printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
  }
  return 0;
}
