#include <bits/stdc++.h>
using namespace std;
const int MX = 1000001;
const int MI = 100001;
const int MT = 10001;
int a[1001][1001];
bool used[1001][1001] = {false};
int main() {
  int n, k;
  cin >> n >> k;
  int m = (n * (n - 1)) / 2;
  if (n * k > m) {
    cout << -1 << endl;
    return 0;
  }
  cout << n * k << endl;
  int t = n * k, kol = 0;
  for (int i = 1; i <= n; ++i) {
    int kol = 0;
    for (int j = 1; j <= n; ++j) {
      if (i == j) continue;
      int u = 0;
      int x = i, y = j;
      if (x > y) swap(x, y), u = 1;
      if (!used[x][y]) {
        used[x][y] = true;
        if (u == 1) swap(x, y);
        printf("%d %d\n", x, y);
        kol++;
      }
      if (kol == k) break;
    }
  }
  return 0;
}
