#include <bits/stdc++.h>
using namespace std;
int deg[1000];
bool play[1000][1000];
vector<pair<int, int> > sol;
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0, _n = n; i < _n; i++) {
    for (int j = 0, _n = n; j < _n; j++)
      if (i != j) {
        if (deg[i] == k) break;
        if (!play[i][j]) {
          play[i][j] = play[j][i] = true;
          sol.push_back(make_pair(i + 1, j + 1));
          deg[i]++;
        }
      }
  }
  for (int i = 0, _n = n; i < _n; i++)
    if (deg[i] < k) {
      cout << "-1\n";
      return 0;
    }
  cout << sol.size() << "\n";
  for (int i = 0, _n = sol.size(); i < _n; i++)
    cout << sol[i].first << " " << sol[i].second << "\n";
  return 0;
}
