#include <bits/stdc++.h>
using namespace std;
double pi = 3.1415926536;
const int oo = (int)1e9;
const long long OO = numeric_limits<long long>::max();
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int di[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dj[] = {1, -1, 0, 0, 1, -1, 1, -1};
int arr[1001][1001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  if (n < k * 2 + 1) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= n; j++) {
      arr[j][(j + i - 1) % n + 1] = 1;
    }
  }
  cout << n * k << endl;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (arr[i][j]) cout << i << " " << j << endl;
  }
}
