#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

class Repeater{
    int st;
    int ed;
    int d;
public:
    class rep_iterator{
        int i; int d;
    public:
        rep_iterator(int x, int pd) :i(x), d(pd) {}

        int& operator*(){ return i; }
        bool operator==(const rep_iterator& k) const { return i == k.i; }
        bool operator!=(const rep_iterator& k) const { return i != k.i; }
        rep_iterator& operator++(){ i+=d; return *this; }
    };

    Repeater(int N) :st(0), ed(N), d(1) {}
    Repeater(int b, int e) :st(b), ed(e), d(1) {if(st > ed){ st--; ed--; d = -1; } }
    Repeater(int b, int e, int dif) :st(b), ed(e), d(dif) {}

    rep_iterator begin() const{ return rep_iterator(st, d); }
    rep_iterator end() const{ return rep_iterator(ed, d); }

};

template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
template<class T> using min_queue = p_queue<T, greater<T>>;
template<class T> using max_queue = p_queue<T, less<T>>;

template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }

pair<ll, ll> rec(ll alpha, ll aa){
    ll a1, a2;
    for (int i = 0; i < alpha; ++i) {
        ll c = i;
        ll d = alpha-i;
        if(aa == c * d){
            c = a1;
            d = a2;
        }
    }// i
    return {a1, a2};
}

struct graph{
            int V;
            
            unordered_map<int, unordered_set<int>> E;
            
            graph(int N) :V(N) {
                for (int i = 0; i < N; ++i) {
                    for (int j = 0; j < N; ++j) {
                        if(i == j) continue;
                        E[i].insert(j);
                    }// j
                }// i
            }
            
            void remove_edge(int a, int b){
                E[a].erase(b);
                E[b].erase(a);
            }
            
            void print(ostream& os){
                int M = 0;
                for (auto &&e : E) {
                    M += e.second.size();
                } // e
                M /= 2;
                cout << M << endl;
                unordered_set<int> outed;
                for (auto &&uv : E) {
                    int u = uv.first;
                    outed.insert(u);
                    for (auto &&v : uv.second) {
                        if(outed.count(v) == 0){
                            cout << u+1 << ' ' << v+1 << endl;
                        }
                    } // v
                } // uv
            }
        };



void sub_main(istream &cin) {
    ll N, K;
    cin >> N >> K;
    if(!cin) return;
    
    if(K >= 0 and K <= (N-1) * (N-2) / 2){
        int now = 0;
        graph G(N);
        if(now == K){
            G.print(cout);
            return;
        }
        for (int i = 1; i < N; ++i) {
            for (int j = i+1; j < N; ++j) {
                now++;
                G.remove_edge(i, j);
                if(now == K){
                    G.print(cout);
                    return;
                }
            }// j
        }// i
    }
    else{
        cout << -1 << endl;
    }
    
    
    

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test_E.txt";
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 768