#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> v(300005);
vector<vector<long long>> v4;
long long col[300005];
map<pair<long long, long long>, long long> mp1;
map<long long, long long> mp3;
long long vis[300005];
long long par[300005];
vector<pair<long long, long long>> v1;
long long price[300005];
long long n, m, k;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  cin >> n >> k;
  long long val = n;
  for (int i = 1; i <= n; i++) {
    int cnt = k;
    for (int j = 1; j <= n && cnt; j++) {
      if (j != i && !mp1[{i, j}]) {
        mp1[{i, j}] = 1;
        mp1[{j, i}] = 1;
        v1.push_back({i, j});
        cnt--;
        val--;
      }
    }
    if (cnt != 0) {
      cout << "-1";
      return 0;
    }
  }
  cout << v1.size() << "\n";
  for (auto i : v1) {
    cout << i.first << " " << i.second << "\n";
  }
  return 0;
}
