#include <bits/stdc++.h>
using namespace std;
int gcd(int u, int v) { return (v != 0) ? gcd(v, u % v) : u; }
int main() {
  int n, k;
  cin >> n >> k;
  vector<set<int> > res(n);
  for (int i = 0; i < n; i++) {
    int counter = 0;
    for (int j = 0; j < n; j++) {
      if (j == i) continue;
      if (counter == k) break;
      if (res[j].count(i) || res[i].count(j)) continue;
      res[i].insert(j);
      counter++;
    }
    if (counter < k) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << n * k << endl;
  for (int i = 0; i < n; i++) {
    set<int>::iterator itr = res[i].begin();
    for (itr; itr != res[i].end(); itr++) {
      printf("%d %d\n", i + 1, (*itr) + 1);
    }
  }
}
