#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
void check_time() {}
const int res = 1e5 + 10;
const int mod = 1e9;
bool mark[1005][1005];
vector<int> graph[res];
int main() {
  int n, k, sum, total, ans, digit = 0;
  vector<pair<int, int> > v;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    digit = 0;
    for (int j = 1; j <= n; j++) {
      if (digit == k) {
        break;
      }
      if (mark[i][j] == true or mark[j][i] == true or i == j) {
        continue;
      }
      mark[i][j] = mark[j][i] = true;
      graph[i].push_back(j);
      digit++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (graph[i].size() == k) {
      continue;
    }
    deb("-1");
    return 0;
  }
  deb(n * k);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < graph[i].size(); j++) {
      deb(i, graph[i][j]);
    }
  }
  return 0;
}
