#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> mm;
vector<pair<int, int> > v;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  if (n == 1) {
    cout << -1;
    return 0;
  }
  int x = 2;
  for (int i = 1; i <= n; i++) {
    int x = i + 1;
    int y = 0;
    while (y < m) {
      if (x > n) x -= n;
      if (mm[{min(i, x), max(i, x)}] == 1 || i == x) {
        cout << -1;
        return 0;
      }
      mm[{min(i, x), max(i, x)}] = 1;
      v.push_back({i, x});
      y++;
      x++;
    }
  }
  cout << v.size() << "\n";
  for (auto i : v) cout << i.first << " " << i.second << "\n";
}
