#include <bits/stdc++.h>
using namespace std;
class C_ {};
template <typename T>
C_& operator<<(C_& m, const T& s) {
  if (!1) cerr << "\E[91m" << s << "\E[0m";
  return m;
}
C_ merr;
bool u[1111][1111];
int C[1111];
int main(void) {
  int n, k;
  vector<pair<int, int> > R;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    if (C[i] >= k) continue;
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      if (!u[i][j]) {
        R.push_back(make_pair(i + 1, j + 1));
        C[i]++;
        u[i][j] = u[j][i] = 1;
      }
      if (C[i] >= k) break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (C[i] != k) {
      cout << "-1" << '\n';
      return 0;
    }
  }
  cout << R.size() << '\n';
  for (int i = 0; i < (int)R.size(); i++) {
    cout << R[i].first << " " << R[i].second << '\n';
  }
  merr << "Execution time: " << fixed << setprecision(3)
       << (double)clock() / CLOCKS_PER_SEC << " s.\n";
  return 0;
}
