#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1.0);
const double EPS = 1E-9;
const int INF = 2 * (1e+9) + 1;
const int NMAX = 1000000;
const int MOD = (1e+9) + 7;
int n, k;
int g[1201][1201];
int cc[1201];
int main() {
  cin >> n >> k;
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (n); ++j) {
      if (i == j) continue;
      if (g[i][j] == 0) {
        g[i][j] = 1;
        g[j][i] = -1;
        cc[i]++;
        if (cc[i] == k) break;
      }
    }
  }
  for (int i = 0; i < (n); ++i) {
    if (cc[i] != k) {
      cout << -1;
      return 0;
    }
  }
  cout << n * k << "\n";
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (n); ++j)
      if (g[i][j] == 1) cout << i + 1 << " " << j + 1 << "\n";
}
