#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
bool used[N][N];
int main() {
  int n, m, i, j;
  cin >> n >> m;
  vector<pair<int, int> > ans;
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) {
      int x = j;
      int y = (j + i);
      if (y > n) y -= n;
      bool ok = 1;
      while (x != y) {
        if (!used[x][y]) {
          used[x][y] = 1;
          used[y][x] = 1;
          ans.push_back(make_pair(x, y));
          ok = 0;
          break;
        }
        y++;
        if (y == n + 1) y = 1;
      }
      if (ok) {
        puts("-1");
        return 0;
      }
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
}
