#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
int played[1111];
int cnt[1111];
int vis[1111][1111];
int main() {
  std::ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int> > ans;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (i == j) continue;
      if (vis[i][j] == 0) {
        if (cnt[i] < k) {
          vis[i][j] = 1;
          vis[j][i] = 1;
          cnt[i]++;
          ans.push_back(make_pair(i, j));
        } else
          break;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (cnt[i] != k) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << int((ans).size()) << endl;
  sort((ans).begin(), (ans).end());
  for (int i = 0; i < int((ans).size()); ++i) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}
