#include <bits/stdc++.h>
using namespace std;
bool m[1001][1001];
bool ff[1001][1001];
int n, num;
int ans;
int main() {
  cin >> n >> num;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= i + num; j++)
      if (!m[i][(j - 1) % n + 1]) {
        m[i][(j - 1) % n + 1] = true;
        m[(j - 1) % n + 1][i] = true;
        ff[i][(j - 1) % n + 1] = true;
      } else {
        cout << -1 << endl;
        return 0;
      }
  if (n == 1) {
    cout << -1 << endl;
    return 0;
  }
  cout << num * n << endl;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (ff[i][j]) printf("%d %d\n", i, j);
}
