#include <bits/stdc++.h>
using namespace std;
const long long N = 1000 + 5;
long long n, k, ar[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  if (n * k > (n * (n - 1)) / 2) {
    cout << "-1";
  } else {
    cout << n * k << "\n";
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        bool us = 0;
        if (ar[i] < k) {
          us = 1;
          ar[i]++;
          cout << i << " " << j << "\n";
        }
        if (ar[j] < k && !us) {
          ar[j]++;
          cout << j << " " << i << "\n";
        }
        if (ar[i] == k && ar[j] == k) break;
      }
    }
  }
}
