#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)1e5 + 7;
const long long MOD = (long long)1e9 + 7;
const long long inf = (long long)1e9 + 7;
const long long INF = (long long)1e18 + 7;
long long n, k;
void solve() {
  cin >> n >> k;
  if (n * k > n * (n - 1) / 2) cout << "-1\n", exit(0);
  cout << n * k << "\n";
  for (long long i = 1; i <= n; ++i) {
    if (i + k > n) {
      for (long long j = i + 1; j <= n; ++j) cout << i << ' ' << j << "\n";
      for (long long j = 1; j <= k - (n - i); ++j)
        cout << i << ' ' << j << "\n";
    } else {
      for (long long j = i + 1; j <= i + k; ++j) {
        cout << i << ' ' << j << "\n";
      }
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  for (long long i = 1; i <= test; i++) {
    solve();
  }
  return 0;
}
