#include <bits/stdc++.h>
using namespace std;
bool adj[1005][1005];
int n, k;
queue<int> q;
vector<pair<int, int> > v;
int main() {
  while (~scanf("%d %d", &n, &k)) {
    bool flag = true;
    if (n == 1) flag = false;
    memset(adj, 0, sizeof(adj));
    while (!q.empty()) q.pop();
    v.clear();
    for (int i = 1; i <= n; i++) q.push(i);
    while (!q.empty()) {
      int tmp = q.front();
      q.pop();
      int kt = k;
      for (int i = 1; i <= n && kt; i++)
        if (i != tmp && !adj[tmp][i]) {
          adj[tmp][i] = adj[i][tmp] = 1;
          kt--;
          v.push_back(make_pair(tmp, i));
        }
      if (kt) {
        flag = false;
        break;
      }
    }
    if (!flag)
      puts("-1");
    else {
      printf("%d\n", v.size());
      for (unsigned int i = 0; i < v.size(); i++)
        printf("%d %d\n", v[i].first, v[i].second);
    }
  }
  return 0;
}
