#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long int MOD = 1000000007;
double eps = 1e-12;
void solve();
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  if (n < 2 * k + 1) {
    cout << -1 << endl;
    return;
  }
  cout << n * k << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      int next = (i + j + 1) % n;
      printf("%d %d\n", i + 1, next + 1);
    }
  }
}
