#include <bits/stdc++.h>
using namespace std;
struct Solution {
  template <typename T>
  void read(T& v) {
    for (auto& x : v) {
      cin >> x;
    }
  }
  int n;
  vector<vector<int> > g;
  void get(int u) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        g[i][j] = 0;
      }
    }
    for (int i = u; i < n; ++i) {
      for (int j = u; j < n; ++j) {
        g[i][j] = 1;
      }
    }
    for (int i = 0; i <= u; ++i) {
      g[i][i + 1] = g[i + 1][i] = 1;
    }
    for (int i = 0; i < n; ++i) {
      g[i][i] = 2;
    }
  }
  void print() {
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        if (g[i][j] == 1) {
          ++cnt;
        }
      }
    }
    cout << cnt << endl;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        if (g[i][j] == 1) {
          cout << i + 1 << " " << j + 1 << endl;
        }
      }
    }
  }
  void solve() {
    int k;
    cin >> n >> k;
    int arr[] = {-1, -1, 3};
    g.assign(n, vector<int>(n));
    for (int i = 0; i < n - 1; ++i) {
      int a = 2;
      int b = i + 1;
      if (i <= 2) a = arr[i];
      int d = min(a, b);
      if (d == k) {
        get(i);
        print();
        return;
      }
    }
    cout << -1 << endl;
  }
};
int main(void) {
  ios_base::sync_with_stdio(false);
  Solution().solve();
  return 0;
}
