#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int N6 = 1e6 + 6;
const int N9 = 1e9 + 7;
const long long INFLL = (long long)1e18 + 100;
const int INF = 1e9 + 100;
const long long mod = 1e9 + 9;
const long long P = 31;
int n, k, cur, ans;
std::vector<int> g[1111];
map<pair<int, int>, bool> cnt;
void solve() {
  cin >> n >> k;
  int cur;
  for (int i = 1; i <= n; ++i) {
    cur = 0;
    for (int j = 1; j <= n; ++j) {
      if (!cnt.count(make_pair(i, j)) && i != j) {
        ++cur;
        cnt[make_pair(i, j)];
        cnt[make_pair(j, i)];
        g[i].push_back(j);
        ++ans;
      }
      if (cur == k) {
        break;
      }
    }
    if (cur != k) {
      cout << -1;
      exit(0);
    }
  }
  cout << ans << '\n';
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < g[i].size(); ++j) {
      cout << i << ' ' << g[i][j] << '\n';
    }
  }
}
int main() {
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
