   //                                                   Practice is th key !
//                                                      @shivamisation

#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (ll) 998244353
#define MOD (ll) 1e9+7
#define all(a) a.begin(),a.end()
#define for0(i, n) for (ll i = 0; i < n; i++)
#define for1(i, n) for (ll i = 1; i <= n; i++)
#define loop(i,a,b) for (ll i = a; i <= b; i++)
#define bloop(i,a,b) for (ll i = a ; i>=b;i--)
#define tc ll t; cin >> t; while (t--)
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define ff first
#define ss second
#define oj    freopen("input.txt", "r",stdin);  freopen("output.txt", "w",stdout)
#define endl "\n"
#define pll pair<ll, ll>
#define mem(a,b)     memset(a,b,sizeof(a))
#define maxx         100001
#define inf          INT_MAX
#define zer          INT_MIN
#define vp vector<pll>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define nl cout<<endl
const ll MAXN = (ll)((1e5) + 100);
void pr(ll x) {cout << x;}
void prl(ll x) {cout << x << endl;}

void solve()
{
	string a ; cin>>a ;
	int n = a.size() ;

	bool ok1 ,ok2 ,ok3=1; ;

	for(int i = 0 ; i <n-1 ;i++)
	{
		if(a[i]=='A' && a[i+1]=='B') ok1=1 ;

		if(a[i]=='B' && a[i+1]=='A') ok2=1 ;

	}

	for(int i = 0 ; i<n-2 ; i++)
	{
		if(a[i]=='A' && a[i+1]=='B' && a[i+2]=='A') ok3=0;
		if(a[i]=='B' && a[i+1]=='A' && a[i+2]=='B') ok3=0;
	}

	if(ok1 && ok2 && ok3) cout<<"YES" ;
	else cout<<"NO"<<endl;

}

int main()
{

#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif

    fio;
    //srand(time(NULL));
    int T = 1;
    //cin >> T;

    while (T--){
    solve();
}

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s.length()<4){
        cout<<"NO";
        return 0;
    }
    int abf=0,baf=0;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]=='A'&&s[i+1]=='B'){
            abf=1;
            i++;
            if(baf)
                break;
        }
        else if(s[i]=='B'&&s[i+1]=='A'){
            baf=1;
            i++;
            if(abf)
                break;
        }
    }
    if(abf&&baf)
        cout<<"YES";
    else
    {
        cout<<"NO";
    }

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s.length()<=4){
        if(s.length()==4&&s=="ABBA")
            cout<<"YES";
        else
            cout<<"NO";
        return 0;
    }
    int abf=0,baf=0,abaf=0,babf=0;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]=='A'&&s[i+1]=='B'){
            if(i+2<s.length()&&s[i+2]=='A')
                abaf+=1;
            abf+=1;
            i++;
        }
        else if(s[i]=='B'&&s[i+1]=='A'){
            if(i+2<s.length()&&s[i+2]=='A')
                babf+=1;
            baf+=1;
            i++;
        }
    }
    if((abaf && abf>abaf)||(babf==1 && baf>babf))
        cout<<"YES";
    else if(abf&&baf)
        cout<<"YES";
    else
    {
        cout<<"NO";
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s.length()<=4){
        if(s.length()==4&&(s=="ABBA"||s=="BAAB"))
            cout<<"YES";
        else
            cout<<"NO";
        return 0;
    }
    int abf=0,baf=0,abaf=0,babf=0,ababf=0,babaf=0;
    for(int i=0;i<s.length()-1;i++){
        if(i+3<s.length()&&s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='A'&&s[i+3]=='B')
            ababf+=1;
        if(i+3<s.length()&&s[i]=='B'&&s[i+1]=='A'&&s[i+2]=='B'&&s[i+3]=='A')
            babaf+=1;
        if(s[i]=='A'&&s[i+1]=='B'){
            if(i+2<s.length()&&s[i+2]=='A')
                abaf+=1;
            abf+=1;
            i++;
        }
        else if(s[i]=='B'&&s[i+1]=='A'){
            if(i+2<s.length()&&s[i+2]=='B')
                babf+=1;
            baf+=1;
            i++;
        }
    }
    if(ababf==1 || babaf==1)
        cout<<"NO";
    else if(abaf>1 ||babf>1)
        cout<<"YES";
    else if((abaf && abf>abaf)||(babf && baf>babf))
        cout<<"YES";
    else if(abf&&baf)
        cout<<"YES";
    else
    {
        cout<<"NO";
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s.length()<=4){
        if(s.length()==4&&(s=="ABBA"||s=="BAAB"))
            cout<<"YES";
        else
            cout<<"NO";
        return 0;
    }
    int abf=0,baf=0,abaf=0,babf=0;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]=='A'&&s[i+1]=='B'){
            if(i+2<s.length()&&s[i+2]=='A')
                abaf+=1;
            abf+=1;
            i++;
        }
        else if(s[i]=='B'&&s[i+1]=='A'){
            if(i+2<s.length()&&s[i+2]=='A')
                babf+=1;
            baf+=1;
            i++;
        }
    }
    if((abaf && abf>abaf)||(babf==1 && baf>babf))
        cout<<"YES";
    else if(abf&&baf)
        cout<<"YES";
    else
    {
        cout<<"NO";
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s.length()<=4){
        if(s.length()==4&&(s=="ABBA"||s=="BAAB"))
            cout<<"YES";
        else
            cout<<"NO";
        return 0;
    }
    int abf=0,baf=0,abaf=0,babf=0,ababf=0,babaf=0;
    for(int i=0;i<s.length()-1;i++){
        if(i+3<s.length()&&s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='A'&&s[i+3]=='B')
            ababf+=1;
        if(i+3<s.length()&&s[i]=='B'&&s[i+1]=='A'&&s[i+2]=='B'&&s[i+3]=='A')
            babaf+=1;
        if(s[i]=='A'&&s[i+1]=='B'){
            if(i+2<s.length()&&s[i+2]=='A')
                abaf+=1;
            abf+=1;
            i++;
        }
        else if(s[i]=='B'&&s[i+1]=='A'){
            if(i+2<s.length()&&s[i+2]=='B')
                babf+=1;
            baf+=1;
            i++;
        }
    }
    if(abaf>1 ||babf>1)
        cout<<"YES";
    else if(ababf==1 || babaf==1)
        cout<<"NO";
    else if((abaf && abf>abaf)||(babf && baf>babf))
        cout<<"YES";
    else if(abf&&baf)
        cout<<"YES";
    else
    {
        cout<<"NO";
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s.length()<4){
        cout<<"NO";
        return 0;
    }
    int abf=0,baf=0,abaf=0,babf=0;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]=='A'&&s[i+1]=='B' && abf==0){
            if(i+2<s.length()&&s[i+2]=='A')
                abaf+=1;
            abf=1;
            i++;
            if(baf)
                break;
        }
        else if(s[i]=='B'&&s[i+1]=='A' && baf==0){
            if(i+2<s.length()&&s[i+2]=='A')
                babf+=1;
            baf=1;
            i++;
            if(abf)
                break;
        }
    }
    if((abaf && abf>abaf )||(babf==1 && baf>babf))
        cout<<"YES";
    else if(abf&&baf)
        cout<<"YES";
    else
    {
        cout<<"NO";
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s.length()<=4){
        if(s.length()==4&&(s=="ABBA"||s=="BAAB"))
            cout<<"YES";
        else
            cout<<"NO";
        return 0;
    }
    int abf=0,baf=0,abaf=0,babf=0,ababf=0,babaf=0;
    for(int i=0;i<s.length()-1;i++){
        if(i+3<s.length()&&s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='A'&&s[i+3]=='B')
            ababf+=1;
        if(i+3<s.length()&&s[i]=='B'&&s[i+1]=='A'&&s[i+2]=='B'&&s[i+3]=='A')
            babaf+=1;
        if(s[i]=='A'&&s[i+1]=='B'){
            if(i+2<s.length()&&s[i+2]=='A')
                abaf+=1;
            abf+=1;
            i++;
        }
        else if(s[i]=='B'&&s[i+1]=='A'){
            if(i+2<s.length()&&s[i+2]=='B')
                babf+=1;
            baf+=1;
            i++;
        }
    }
    if(abaf>1 ||babf>1)
        cout<<"YES";
    else if((ababf==1 && abf==2 )|| (babaf==1 && baf==2))
        cout<<"NO";
    else if((abaf && abf>abaf)||(babf && baf>babf))
        cout<<"YES";
    else if(abf&&baf)
        cout<<"YES";
    else
    {
        cout<<"NO";
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s.length()<=4){
        if(s.length()==4&&(s=="ABBA"||s=="BAAB"))
            cout<<"YES";
        else
            cout<<"NO";
        return 0;
    }
    int abf=0,baf=0,abaf=0,babf=0;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]=='A'&&s[i+1]=='B'){
            if(i+2<s.length()&&s[i+2]=='A')
                abaf+=1;
            abf+=1;
            i++;
        }
        else if(s[i]=='B'&&s[i+1]=='A'){
            if(i+2<s.length()&&s[i+2]=='B')
                babf+=1;
            baf+=1;
            i++;
        }
    }
    if(abaf>1 ||babf>1)
        cout<<"YES";
    else if((abaf && abf>abaf)||(babf && baf>babf))
        cout<<"YES";
    else if(abf&&baf)
        cout<<"YES";
    else
    {
        cout<<"NO";
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s.length()<4){
        cout<<"NO";
        return 0;
    }
    int abf=0,baf=0;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]=='A'&&s[i+1]=='B' && abf==0){
            abf=1;
            i++;
            if(baf)
                break;
        }
        else if(s[i]=='B'&&s[i+1]=='A' && baf==0){
            baf=1;
            i++;
            if(abf)
                break;
        }
    }
    if(abf&&baf)
        cout<<"YES";
    else
    {
        cout<<"NO";
    }

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s.length()<4){
        cout<<"NO";
        return 0;
    }
    int abf=0,baf=0,abaf=0,babf=0;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]=='A'&&s[i+1]=='B' && abf==0){
            if(i+2<s.length()&&s[i+2]=='A')
                abaf=1;
            abf=1;
            i++;
            if(baf)
                break;
        }
        else if(s[i]=='B'&&s[i+1]=='A' && baf==0){
            if(i+2<s.length()&&s[i+2]=='A')
                babf=1;
            baf=1;
            i++;
            if(abf)
                break;
        }
    }
    if((abaf && abf )||(babf && baf))
        cout<<"YES";
    else if(abf&&baf)
        cout<<"YES";
    else
    {
        cout<<"NO";
    }

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s.length()<4){
        cout<<"NO";
        return 0;
    }
    int abf=0,baf=0,abaf=0,babf=0;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]=='A'&&s[i+1]=='B'){
            if(i+2<s.length()&&s[i+2]=='A')
                abaf+=1;
            abf+=1;
            i++;
        }
        else if(s[i]=='B'&&s[i+1]=='A'){
            if(i+2<s.length()&&s[i+2]=='A')
                babf+=1;
            baf+=1;
            i++;
        }
    }
    if((abaf && abf>abaf)||(babf==1 && baf>babf))
        cout<<"YES";
    else if(abf&&baf)
        cout<<"YES";
    else
    {
        cout<<"NO";
    }
}


#include<bits/stdc++.h>
//#include<unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
//#define int long long
#define die(x) return cout << x << endl, 0
#define FI first
#define SE second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define FILE freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define SZ(x) ((int)(x).size())
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define MP make_pair
#define FR front
#define BK back
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef map<int,int> mpi;
typedef set<int> sti;
typedef vector<pii> vii;
typedef map<pii,int> mpii;
typedef set<pii> stii;
typedef long double ld;
typedef long long ll;
int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }
int power(int x, int y) { return (!y ? 1 : power(x, y / 2) * power(x, y / 2) * (y % 2 ? x : 1)); }
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
const int MAXN=3e3+10,MOD=1e9+7;
const double PI = std::atan(1.0)*4;
int mod(int x) { return (x % MOD + MOD) % MOD; }
int n,m,k;
int MAIN(){
    cin>>n>>k;
    if(k>3 || k==1 || ((n==4 || n<3)&& k==2) || (n<4 && k==3))die(-1);
    if(k==2){cout<<n-1<<endl;for(int i=1;i<n;i++)cout<<i<<" "<<i+1<<endl;}
    if(k==3){
        cout<<n-1<<endl;
        for(int i=1;i<=3;i++)cout<<i<<" "<<i+1<<endl;
        if(n>4){
        for(int i=5;i<=n-1;i++)cout<<2<<" "<<i<<endl;
        cout<<3<<" "<<n<<endl;
        }
    }
    return 0;
}
int32_t main(){
    IOS;
    int t=1;
    //cin>>t;
    while(t--)MAIN();
}


#include<bits/stdc++.h>
//#include<unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
//#define int long long
#define die(x) return cout << x << endl, 0
#define FI first
#define SE second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define FILE freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define SZ(x) ((int)(x).size())
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define MP make_pair
#define FR front
#define BK back
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef map<int,int> mpi;
typedef set<int> sti;
typedef vector<pii> vii;
typedef map<pii,int> mpii;
typedef set<pii> stii;
typedef long double ld;
typedef long long ll;
int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }
int power(int x, int y) { return (!y ? 1 : power(x, y / 2) * power(x, y / 2) * (y % 2 ? x : 1)); }
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
const int MAXN=3e3+10,MOD=1e9+7;
const double PI = std::atan(1.0)*4;
int mod(int x) { return (x % MOD + MOD) % MOD; }
int n,m,k;
int MAIN(){
    cin>>n>>k;
    if(k>3 || k==1 || (n==4 && k==2))die(-1);
    if(k==2){cout<<n-1<<endl;for(int i=1;i<n;i++)cout<<i<<" "<<i+1<<endl;}
    if(k==3){
        cout<<n-1<<endl;
        for(int i=1;i<=3;i++)cout<<i<<" "<<i+1<<endl;
        for(int i=4;i<=n-1;i++)cout<<2<<" "<<i<<endl;
        cout<<3<<" "<<n<<endl;
    }
    return 0;
}
int32_t main(){
    IOS;
    int t=1;
    //cin>>t;
    while(t--)MAIN();
}


#include<bits/stdc++.h>
//#include<unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
//#define int long long
#define die(x) return cout << x << endl, 0
#define FI first
#define SE second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define FILE freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define SZ(x) ((int)(x).size())
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define MP make_pair
#define FR front
#define BK back
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef map<int,int> mpi;
typedef set<int> sti;
typedef vector<pii> vii;
typedef map<pii,int> mpii;
typedef set<pii> stii;
typedef long double ld;
typedef long long ll;
int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }
int power(int x, int y) { return (!y ? 1 : power(x, y / 2) * power(x, y / 2) * (y % 2 ? x : 1)); }
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
const int MAXN=3e3+10,MOD=1e9+7;
const double PI = std::atan(1.0)*4;
int mod(int x) { return (x % MOD + MOD) % MOD; }
int n,m,k;
int MAIN(){
    cin>>n>>k;
    if(k>3 || k==1 || ((n==4 || n<3)&& k==2))die(-1);
    if(k==2){cout<<n-1<<endl;for(int i=1;i<n;i++)cout<<i<<" "<<i+1<<endl;}
    if(k==3){
        cout<<n-1<<endl;
        for(int i=1;i<=3;i++)cout<<i<<" "<<i+1<<endl;
        if(n>4){
        for(int i=5;i<=n-1;i++)cout<<2<<" "<<i<<endl;
        cout<<3<<" "<<n<<endl;
        }
    }
    return 0;
}
int32_t main(){
    IOS;
    int t=1;
    //cin>>t;
    while(t--)MAIN();
}


#include<bits/stdc++.h>
//#include<unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
//#define int long long
#define die(x) return cout << x << endl, 0
#define FI first
#define SE second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define FILE freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define SZ(x) ((int)(x).size())
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define MP make_pair
#define FR front
#define BK back
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef map<int,int> mpi;
typedef set<int> sti;
typedef vector<pii> vii;
typedef map<pii,int> mpii;
typedef set<pii> stii;
typedef long double ld;
typedef long long ll;
int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }
int power(int x, int y) { return (!y ? 1 : power(x, y / 2) * power(x, y / 2) * (y % 2 ? x : 1)); }
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
const int MAXN=3e3+10,MOD=1e9+7;
const double PI = std::atan(1.0)*4;
int mod(int x) { return (x % MOD + MOD) % MOD; }
int n,m,k;
int MAIN(){
    cin>>n>>k;
    if(k>3 || k==1 || ((n==4 || n<3)&& k==2) || (n<4 && k==3))qdie(-1);
    if(k==2){cout<<n-1<<endl;for(int i=1;i<n;i++)cout<<i<<" "<<i+1<<endl;}
    if(k==3){
        cout<<n-1<<endl;
        for(int i=1;i<=3;i++)cout<<i<<" "<<i+1<<endl;
        if(n>4){
        for(int i=5;i<=n-1;i++)cout<<2<<" "<<i<<endl;
        cout<<3<<" "<<n<<endl;
        }
    }
    return 0;
}
int32_t main(){
    IOS;
    int t=1;
    //cin>>t;
    while(t--)MAIN();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
void solve(){
	ll n,k;
	cin>>n>>k;
	if(n<4||k==1||k>3||(n==4&&k==2)){
		cout<<"-1";
		exit(0);
	}
	if(k==2){
		cout<<n-1<<"\n";
		for(ll i=1;i<n;i++)
		cout<<i<<" "<<i+1<<"\n";
	}
	else{
		vector<p2> res;
		for(ll i=1;i<4;i++)
		res.push_back({i,i+1});
		for(ll i=5;i<=n;i++){
			res.push_back({i,1});
			res.push_back({i,3});
		}
		cout<<res.size()<<"\n";
		for(ll i=0;i<ll(res.size());i++)
		cout<<res[i].first<<" "<<res[i].second<<"\n";
	}
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
//~ #pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define erase_duplicates(x) sort(all(x)); (x).resize(distance((x).begin(), unique(all(x))));

using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<
T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#define cerr if(0)cout
#endif

const int maxn = (1e6)+7;
const int maxk = 20;
const int inf = (1e9)+7;
const LL LLinf = ((LL)1e18)+7LL;
const LD eps = 1e-9;
const LL mod = 1e9+7;

// ***************************** CODE ***************************** //

int main()
{
	_upgrade
  int n, k;
  cin>>n>>k;
  if(k == 1)
  {
    cout<<-1;
    return 0;
  }
  if(k == 2)
  {
    if(n <= 4)
    {
      cout<<-1;
      return 0;
    }
    cout<<n-1<<endl;
    for(int i = 1;i < n;i++)
      cout<<i<<" "<<i + 1<<"\n";
    return 0;
  }
  if(k == 3)
  {
    if(n >= 4)
    {
      cout<<n - 1<<"\n";
      cout<<"1 3\n2 4\n1 4\n";
      for(int i = 5;i <= n;i++)
        cout<<i<<" 4\n";
    }
    else
      cout<<-1;
    return 0;
  }
  cout<<-1;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int n,k;

int32_t main()
{
    IOS
    cin>>n>>k;
    if (k==1||k>=4) return cout<<-1<<endl,0;
    if (k==2)
    {
    	if (n<=4) cout<<-1<<endl;
    	else
    	{
    		cout<<n-1<<endl;
    		for (int i=1;i<=n-1;i++) cout<<i<<' '<<i+1<<endl;
		}
	}
	if (k==3)
	{
		if (n<=3) cout<<-1<<endl;
		else
		{
			cout<<(n-4)*2+3+(n-4)*(n-5)/2<<endl;
			cout<<1<<' '<<2<<endl;
			cout<<2<<' '<<3<<endl;
			cout<<3<<' '<<4<<endl;
			for (int i=5;i<=n;i++)
			{
				cout<<i<<' '<<1<<endl;
				cout<<i<<' '<<3<<endl;
			}
			for (int i=6;i<=n;i++)
				for (int j=5;j<i;j++) cout<<i<<' '<<j<<endl;
		}
	}
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define sync()      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F           first
#define S           second
#define mp          make_pair
#define ers         erase
#define ins         insert
#define db          pop_back
#define pb          push_back
#define df          pop_front
#define pf          push_front
#define sqr(x)      (x)*(x)
#define Blz(x)      __builtin_clz(x)
#define Brz(x)      __builtin_ctz(x)
#define Bones(x)    __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define kill(x)     return cout<<x,0
#define dbgp(x)     cerr<< #x << " = " << x.F << ", " << x.S << endl
#define dbg(x)      cerr<< #x << " = " << x << endl
#define ddbg(i,x)   cerr<< #i << " = " << i << " / "; dbg(x[i])
#define tdbg(i,j,x) cerr<< #i << " = " << i << " / "; ddbg(j,x[i])
typedef long long                                 ll;
typedef long double                               ld;
typedef unsigned short int                        usi;
typedef pair<long long,bool>                      plb;
typedef pair<long long,long long>                 pll;
typedef string                                    str;
typedef priority_queue<ll>                        maxheap;
typedef priority_queue<ll,vector<ll>,greater<ll>> minheap;
const ll maxn=1e3+10, inf=4e18, mod=1e9+7; const ld pi=3.14159265359, eps=1e-9;
int main(){
    sync();
    ll n,k; cin>>n>>k;
    if(k>3 || k==1 || k>=n) kill(-1);
    else if(k==3){
        cout<<2*(n-3)+1<<endl;
        cout<<"1 2"<<endl; for(int i=4;i<=n;i++){ cout<<i<<" 2"<<endl; cout<<i<<" 3"<<endl; }
    }
    else{
        if(n<=4) kill(-1);
        cout<<n-1<<endl;
        for(int i=1;i<=n-1;i++){ cout<<i<<' '<<i+1<<endl; }
    }
    return 0;
}
/**
 (                            )   (   )
 )\ )             (      )  ( /(  () /(
(()/(  (  (    (  )\  ( /(  )\()) )\ ())
 /(_))_)  )\   )\((_) )(_))(_)\) ((_)(_)
(_)) __| ((_) ((_)| |((_)_)| |(_)| |_| |
  | (_ |/ _ \/ _ \| |/ _` || / / |  _  |
   \___|\___/\___/|_|\__,_||_\_\ |_| |_|
**/


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define sync()      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F           first
#define S           second
#define mp          make_pair
#define ers         erase
#define ins         insert
#define db          pop_back
#define pb          push_back
#define df          pop_front
#define pf          push_front
#define sqr(x)      (x)*(x)
#define Blz(x)      __builtin_clz(x)
#define Brz(x)      __builtin_ctz(x)
#define Bones(x)    __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define kill(x)     return cout<<x,0
#define dbgp(x)     cerr<< #x << " = " << x.F << ", " << x.S << endl
#define dbg(x)      cerr<< #x << " = " << x << endl
#define ddbg(i,x)   cerr<< #i << " = " << i << " / "; dbg(x[i])
#define tdbg(i,j,x) cerr<< #i << " = " << i << " / "; ddbg(j,x[i])
typedef long long                                 ll;
typedef long double                               ld;
typedef unsigned short int                        usi;
typedef pair<long long,bool>                      plb;
typedef pair<long long,long long>                 pll;
typedef string                                    str;
typedef priority_queue<ll>                        maxheap;
typedef priority_queue<ll,vector<ll>,greater<ll>> minheap;
const ll maxn=1e3+10, inf=4e18, mod=1e9+7; const ld pi=3.14159265359, eps=1e-9;
int main(){
    sync();
    ll n,k; cin>>n>>k;
    if(k>3 || k==1 || k>=n) kill(-1);
    else if(k==3){
        cout<<2*(n-3)+1<<endl;
        cout<<"1 2"<<endl; for(int i=4;i<=n;i++){ cout<<i<<" 2"<<endl; cout<<i<<" 3"<<endl; }
    }
    else{
        if(n==4) kill(-1);
        cout<<n-1<<endl;
        for(int i=1;i<=n-1;i++){ cout<<i<<' '<<i+1<<endl; }
    }
    return 0;
}
/**
 (                            )   (   )
 )\ )             (      )  ( /(  () /(
(()/(  (  (    (  )\  ( /(  )\()) )\ ())
 /(_))_)  )\   )\((_) )(_))(_)\) ((_)(_)
(_)) __| ((_) ((_)| |((_)_)| |(_)| |_| |
  | (_ |/ _ \/ _ \| |/ _` || / / |  _  |
   \___|\___/\___/|_|\__,_||_\_\ |_| |_|
**/


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define sync()      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F           first
#define S           second
#define mp          make_pair
#define ers         erase
#define ins         insert
#define db          pop_back
#define pb          push_back
#define df          pop_front
#define pf          push_front
#define sqr(x)      (x)*(x)
#define Blz(x)      __builtin_clz(x)
#define Brz(x)      __builtin_ctz(x)
#define Bones(x)    __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define kill(x)     return cout<<x,0
#define dbgp(x)     cerr<< #x << " = " << x.F << ", " << x.S << endl
#define dbg(x)      cerr<< #x << " = " << x << endl
#define ddbg(i,x)   cerr<< #i << " = " << i << " / "; dbg(x[i])
#define tdbg(i,j,x) cerr<< #i << " = " << i << " / "; ddbg(j,x[i])
typedef long long                                 ll;
typedef long double                               ld;
typedef unsigned short int                        usi;
typedef pair<long long,bool>                      plb;
typedef pair<long long,long long>                 pll;
typedef string                                    str;
typedef priority_queue<ll>                        maxheap;
typedef priority_queue<ll,vector<ll>,greater<ll>> minheap;
const ll maxn=1e3+10, inf=4e18, mod=1e9+7; const ld pi=3.14159265359, eps=1e-9;
int main(){
    sync();
    ll n,k; cin>>n>>k;
    if(k>3 || k==1 || k>=n) kill(-1);
    else if(k==3) cout<<"3\n1 2\n2 3\n3 4";
    else cout<<"2\n1 2\n2 3";
    return 0;
}
/**
 (                            )   (   )
 )\ )             (      )  ( /(  () /(
(()/(  (  (    (  )\  ( /(  )\()) )\ ())
 /(_))_)  )\   )\((_) )(_))(_)\) ((_)(_)
(_)) __| ((_) ((_)| |((_)_)| |(_)| |_| |
  | (_ |/ _ \/ _ \| |/ _` || / / |  _  |
   \___|\___/\___/|_|\__,_||_\_\ |_| |_|
**/


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define sync()      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F           first
#define S           second
#define mp          make_pair
#define ers         erase
#define ins         insert
#define db          pop_back
#define pb          push_back
#define df          pop_front
#define pf          push_front
#define sqr(x)      (x)*(x)
#define Blz(x)      __builtin_clz(x)
#define Brz(x)      __builtin_ctz(x)
#define Bones(x)    __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define kill(x)     return cout<<x,0
#define dbgp(x)     cerr<< #x << " = " << x.F << ", " << x.S << endl
#define dbg(x)      cerr<< #x << " = " << x << endl
#define ddbg(i,x)   cerr<< #i << " = " << i << " / "; dbg(x[i])
#define tdbg(i,j,x) cerr<< #i << " = " << i << " / "; ddbg(j,x[i])
typedef long long                                 ll;
typedef long double                               ld;
typedef unsigned short int                        usi;
typedef pair<long long,bool>                      plb;
typedef pair<long long,long long>                 pll;
typedef string                                    str;
typedef priority_queue<ll>                        maxheap;
typedef priority_queue<ll,vector<ll>,greater<ll>> minheap;
const ll maxn=1e3+10, inf=4e18, mod=1e9+7; const ld pi=3.14159265359, eps=1e-9;
int main(){
    sync();
    ll n,k; cin>>n>>k;
    if(k>3 || k==1 || k>=n) kill(-1);
    else if(k==3){
        cout<<2*(n-3)+1<<endl;
        cout<<"1 2"<<endl; for(int i=4;i<=n;i++){ cout<<i<<" 2"<<endl; cout<<i<<" 3"<<endl; }
    }
    else{
        if(n==4) kill(-1);
        cout<<n<<endl;
        for(int i=1;i<=n-1;i++){ cout<<i<<' '<<i+1<<endl; }
    }
    return 0;
}
/**
 (                            )   (   )
 )\ )             (      )  ( /(  () /(
(()/(  (  (    (  )\  ( /(  )\()) )\ ())
 /(_))_)  )\   )\((_) )(_))(_)\) ((_)(_)
(_)) __| ((_) ((_)| |((_)_)| |(_)| |_| |
  | (_ |/ _ \/ _ \| |/ _` || / / |  _  |
   \___|\___/\___/|_|\__,_||_\_\ |_| |_|
**/


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
#include <unordered_map>
#include <ctime>
typedef  long long ll;
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);}
typedef pair<int, int> pii;
typedef long double ld;
typedef unsigned int uint;
#define MAX 105
bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
string direc="RDLU";
ll ln, lk, lm;
void etp(bool f = 0) {
    puts(f ?"YES" : "NO");
    exit(0);
}
void addmod(int &x, int y, int mod = MOD) {
    x+=y; if (x>=mod) x-=mod;
    assert(x>=0 && x<mod);
}
void et() {
    puts("-1"); exit(0);
}

void fmain(int tid) {
    scanf("%d%d", &n, &k);
    if (k==1||k>=4) et();
    if (k==2) {
        if (n<5) et();
        printf("%d\n",n-1);
        REQ(i,n-1) printf("%d %d\n",i,i+1);
    } else {
        if (n<4) et();
        printf("%d\n",n-1);
        puts("1 2"); puts("2 3");
        for(int i=4;i<=n;i++) {
            printf("%d %d\n",3,i);
        }
    }
}

int main() {
    int t=1;
//    scanf("%d", &t);
    REQ(i,t) {
        fmain(i);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	if (k == 1){
		cout << -1 << endl;
		return 0;
	}

	if (k == 2){
		if (n <= 4){
			cout << -1 << endl;
			return 0;
		}

		cout << n-1 << endl;
		for (int i = 1; i < n; i++)
			cout << i << ' ' << i + 1 << endl;

		return 0;
	}

	if (k == 3){
		if (n <= 7){
			cout << -1 << endl;
			return 0;
		}

		cout << 3 + n - 5 + 2 * (n-4) + 1 + (n-4)*(n-5) / 2 << endl;
		cout << "1 2\n 2 3\n 3 4" << endl;
		for (int i = 5; i < n; i++)
			cout << 1 << ' ' << i << endl;

		for (int i = 2; i <= 3; i++){
			for (int j = 5; j <= n; j++)
				cout << i << ' ' << j << endl;
		}

		cout << 4 << ' ' << n << endl;

		for (int i = 4; i <= n; i++){
			for (int j = i + 1; j <= n; j++)
				cout << i << ' ' << j << endl;
		}

		return 0;
	}

	cout << -1 << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	if (k == 1){
		cout << -1 << endl;
		return 0;
	}

	if (k == 2){
		if (n <= 4){
			cout << -1 << endl;
			return 0;
		}

		cout << n-1 << endl;
		for (int i = 1; i < n; i++)
			cout << i << ' ' << i + 1 << endl;

		return 0;
	}

	if (k == 3){
		if (n <= 7){
			cout << -1 << endl;
			return 0;
		}

		cout << 3 + n - 5 + 2 * (n-4) + 1 + (n-4)*(n-5) / 2 << endl;
		cout << "1 2\n2 3\n3 4" << endl;
		for (int i = 5; i < n; i++)
			cout << 1 << ' ' << i << endl;

		for (int i = 2; i <= 3; i++){
			for (int j = 5; j <= n; j++)
				cout << i << ' ' << j << endl;
		}

		cout << 4 << ' ' << n << endl;

		for (int i = 5; i <= n; i++){
			for (int j = i + 1; j <= n; j++)
				cout << i << ' ' << j << endl;
		}

		return 0;
	}

	cout << -1 << endl;
	return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>k;
	if (k>3 || k==1 || n<=3) kill(-1)
	if (n==4){
		if (k==2) kill(-1)
		cout<<"3\n";
		cout<<"1 2\n";
		cout<<"2 3\n";
		cout<<"3 4\n";
		return 0;
	}
	if (k==2){
		cout<<n-1<<'\n';
		for (int i=1; i<n; i++) cout<<i<<' '<<i+1<<'\n';
		return 0;
	}
	cout<<n-1<<'\n';
	cout<<"1 2\n";
	cout<<"2 3\n";
	for (int i=4; i<=n; i++) cout<<"3 "<<i<<'\n';

	return 0;
}


//Be Name Khoda
//no comment...
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using mordered_set =  tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5 + 7;
const int infint = (int)1e9;
const ll inf = (ll)1e18;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, k;
    cin >> n >> k;
    if(k == 1 || k >= 4 || n <= 3)
    	return cout << -1, 0;

    if(k == 3)
    {
    	cout << n - 1 << "\n";
    	for (int i = 2; i <= n - 1; i++)
    		cout << 1 << " " << i << "\n";
    	cout << 2 << " " << n;
    	return 0;
	}

	if(n == 4)
		return cout << -1, 0;
	cout << 2 * n - 4 << "\n";
	for (int i = 3; i <= n; i++)
		cout << 1 << " " << i << "\n";
	for (int i = 3; i < n; i++)
		cout << 2 << " " << i << "\n";
	cout << n << " " << n - 1;
}


#include<bits/stdc++.h>
using namespace std;

typedef double                 ld;
typedef long long                   ll;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<string , string>       pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define endl                        '\n'
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define kill(x)                     return cout << x << endl , 0;
#define pb                          push_back

const ll MXN = 3e3 + 10;
const ll MXM = 5e2 + 10;
const ll MX5 = 1e5 + 10;
const ll MX6 = 1e6 + 10;
const ll INF = 8e18;
const ld eps = 1e-9;
const ll MOD = 1e9 + 7; //998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}
string base2(ll n){
    string a="";while(n>=2){a+=(char)(n%2+'0');n/=2;}a+=(char)(n+'0');reverse(all(a));return a;
}

int main(){
    fast_io
    //file_io
    ll n, k;
    cin >> n >> k;
    if(k >= 4 || k == 1 || n <= 3) kill(-1);
    if(k == 2){
        cout << n - 1 << endl;
        for(int i = 1; i <= n - 1; i ++){
            cout << i << sep << i + 1  << endl;
        }
    }
    else{
        cout << n - 1 << endl;
        for(int i = 2; i <= n - 1; i ++){
            cout << 1 << sep << i << endl;
        }
        cout << n << sep << 2;
    }

    return 0;
}

//! N.N


#include<bits/stdc++.h>
using namespace std;

typedef double                 ld;
typedef long long                   ll;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<string , string>       pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define endl                        '\n'
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define kill(x)                     return cout << x << endl , 0;
#define pb                          push_back

const ll MXN = 3e3 + 10;
const ll MXM = 5e2 + 10;
const ll MX5 = 1e5 + 10;
const ll MX6 = 1e6 + 10;
const ll INF = 8e18;
const ld eps = 1e-9;
const ll MOD = 1e9 + 7; //998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}
string base2(ll n){
    string a="";while(n>=2){a+=(char)(n%2+'0');n/=2;}a+=(char)(n+'0');reverse(all(a));return a;
}

int main(){
    fast_io
    //file_io
    ll n, k;
    cin >> n >> k;
    if(k >= 4 || k == 1 || n <= 3) kill(-1);
    if(k == 2){
        if(n == 4) kill(-1);
        cout << n - 1 << endl;
        for(int i = 1; i <= n - 1; i ++){
            cout << i << sep << i + 1  << endl;
        }
    }
    else{
        cout << n - 1 << endl;
        for(int i = 2; i <= n - 1; i ++){
            cout << 1 << sep << i << endl;
        }
        cout << n << sep << 2;
    }

    return 0;
}

//! N.N


#include<bits/stdc++.h>
using namespace std;

typedef double                 ld;
typedef long long                   ll;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<string , string>       pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define endl                        '\n'
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define kill(x)                     return cout << x << endl , 0;
#define pb                          push_back

const ll MXN = 3e3 + 10;
const ll MXM = 5e2 + 10;
const ll MX5 = 1e5 + 10;
const ll MX6 = 1e6 + 10;
const ll INF = 8e18;
const ld eps = 1e-9;
const ll MOD = 1e9 + 7; //998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}
string base2(ll n){
    string a="";while(n>=2){a+=(char)(n%2+'0');n/=2;}a+=(char)(n+'0');reverse(all(a));return a;
}

int main(){
    fast_io
    //file_io
    ll n, k;
    cin >> n >> k;
    if(k >= 4 || k == 1 || n <= 4) kill(-1);
    if(k == 2){
        cout << n - 1 << endl;
        for(int i = 1; i <= n - 1; i ++){
            cout << i << sep << i + 1  << endl;
        }
    }
    else{
        cout << n - 1 << endl;
        for(int i = 2; i <= n - 1; i ++){
            cout << 1 << sep << i << endl;
        }
        cout << n << sep << 2;
    }

    return 0;
}

//! N.N


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=1000005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
vector<PR> Ans;
int flag[1005][1005];
signed main()
{
	int n=read(),k=read();
	if (k!=2&&k!=3) { puts("-1"); return 0; }
	if (k==2)
	{
		if (n<=4) { puts("-1"); return 0; }
		Ans.PB(MP(1,2)),Ans.PB(MP(1,3)),Ans.PB(MP(1,4));
		Ans.PB(MP(2,3)),Ans.PB(MP(2,5));
		Ans.PB(MP(4,5));
		for (int i=6,lst=2;i<=n;lst=i,i++)
			for (int j=1;j<i;j++) if (j!=lst) Ans.PB(MP(i,j));
	}
	if (k==3)
	{
		if (n<3) { puts("-1"); return 0; }
		for (int i=1;i<=n-1;i++)
			for (int j=i+1;j<=n-1;j++)
				if (i!=1||j!=2) Ans.PB(MP(i,j));
		Ans.PB(MP(1,n));
	}
	printf("%d\n",Ans.size());
	for (auto v:Ans) printf("%d %d\n",v.fi,v.se);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=1000005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
vector<PR> Ans;
int flag[1005][1005];
signed main()
{
	int n=read(),k=read();
	if (k!=2&&k!=3) { puts("-1"); return 0; }
	for (int i=1;i<=n-k+2;i++)
		for (int j=i+1;j<=n-k+2;j++) flag[i][j]=1;
	flag[1][2]=0;
	int u=1,v=2;
	for (int i=n-k+3;i<=n;i++)
		if (i&1) flag[u][i]=1,u=i;
		else flag[v][i]=1,v=i;

	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
			if (flag[i][j]||flag[j][i]) Ans.PB(MP(i,j));
	printf("%d\n",Ans.size());
	for (auto v:Ans) printf("%d %d\n",v.fi,v.se);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=1000005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
vector<PR> Ans;
int flag[1005][1005];
signed main()
{
	int n=read(),k=read();
	if (k!=2&&k!=3) { puts("-1"); return 0; }
	if (k==2)
	{
		if (n<4) { puts("-1"); return 0; }
		Ans.PB(MP(1,2)),Ans.PB(MP(1,3)),Ans.PB(MP(1,4));
		Ans.PB(MP(2,3)),Ans.PB(MP(2,5));
		Ans.PB(MP(4,5));
		for (int i=6,lst=2;i<=n;lst=i,i++)
			for (int j=1;j<i;j++) if (j!=lst) Ans.PB(MP(i,j));
	}
	if (k==3)
	{
		if (n<3) { puts("-1"); return 0; }
		for (int i=1;i<=n-1;i++)
			for (int j=i+1;j<=n-1;j++)
				if (i!=1||j!=2) Ans.PB(MP(i,j));
		Ans.PB(MP(1,n));
	}
	printf("%d\n",Ans.size());
	for (auto v:Ans) printf("%d %d\n",v.fi,v.se);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=1000005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
vector<PR> Ans;
int flag[1005][1005];
signed main()
{
	int n=read(),k=read();
	if (k!=2&&k!=3) { puts("-1"); return 0; }
	if (k==2)
	{
		if (n<=4) { puts("-1"); return 0; }
		Ans.PB(MP(1,2)),Ans.PB(MP(1,3)),Ans.PB(MP(1,4));
		Ans.PB(MP(2,3)),Ans.PB(MP(2,5));
		Ans.PB(MP(4,5));
		for (int i=6,lst=2;i<=n;lst=i,i++)
			for (int j=1;j<i;j++) if (j!=lst) Ans.PB(MP(i,j));
	}
	if (k==3)
	{
		if (n<=3) { puts("-1"); return 0; }
		for (int i=1;i<=n-1;i++)
			for (int j=i+1;j<=n-1;j++)
				if (i!=1||j!=2) Ans.PB(MP(i,j));
		Ans.PB(MP(1,n));
	}
	printf("%d\n",Ans.size());
	for (auto v:Ans) printf("%d %d\n",v.fi,v.se);
	return 0;
}


///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

void no() {
    cout << "-1\n";
    exit(0);
}

void solve() {
    int n, k;
    cin >> n >> k;

    if (k == 2) {
        if (n >= 5) {
            cout << n - 1 << "\n";
            for (int i = 1; i < n; ++i) {
                cout << i << " " << i + 1 << "\n";
            }
        } else {
            no();
        }
    } else if (k == 3) {
        if (n >= 4) {
            cout << n - 1 << "\n";
            cout << "1 2\n2 3\n";
            for (int i = 4; i <= n; ++i) {
                cout << "3 " << i << "\n";
            }
        } else {
            no();
        }
    } else {
        no();
    }
}

int main() {
    ios::sync_with_stdio(0);
    cout.tie(0), cin.tie(0);

    int z = 1;
    /// cin >> z;

    while (z--) {
        solve();
    }

    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int n,k;
int main() {
	scanf("%d%d",&n,&k);
	if(k==2)
	{
		if(n<=4)return !printf("-1");
		printf("%d\n",n-1);
		fup(i,1,n-1,1)printf("%d %d\n",i,i+1);
		return 0;
	}
	if(k==3)
	{
		if(n<4)return !printf("-1");
		printf("%d\n",(n-2)*(n-3)/2+2);
		fup(i,1,n-2,1)fup(j,i+1,n-2,1)printf("%d %d\n",i,j);
		printf("%d %d\n%d %d\n",n-2,n-1,n-1,n);
		return 0;
	}
	puts("-1");
}


#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;

#define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (st                                  derr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<pii, int> mpii;
typedef set<int> sti;
const int INF = 1e9, MOD = /* INF + 7 */ INF - 1755647;
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
int power(int a, int b) { return (!b ? 1 : power(a, b / 2) * power(a, b / 2) * (b % 2 ? a : 1)); }
int mod(int a) { return (a % MOD + MOD) % MOD; }

/////////////////////////////////////////////////////////////////////

const int N = 2e5 + 20;

int32_t main(){

    sync;

    int n, k; cin >> n >> k;
    if (k == 2 && n > 4) {
        cout << n - 1 << endl;
        for(int i = 1; i < n; i++) cout << i << ends << i + 1 << endl;
    }
    else if (k == 3) {
        cout << 3 + (n - 4) * 2 << endl;
        for(int i = 1; i < 4; i++) cout << i << ends << i + 1 << endl;
        for(int i = 5; i <= n; i++) cout << 2 << ends << i << endl;
        for(int i = 5; i <= n; i++) cout << 3 << ends << i << endl;
    }
    else cout << -1 << endl;

    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;

#define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (st                                  derr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<pii, int> mpii;
typedef set<int> sti;
const int INF = 1e9, MOD = /* INF + 7 */ INF - 1755647;
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
int power(int a, int b) { return (!b ? 1 : power(a, b / 2) * power(a, b / 2) * (b % 2 ? a : 1)); }
int mod(int a) { return (a % MOD + MOD) % MOD; }

/////////////////////////////////////////////////////////////////////

const int N = 2e5 + 20;

int32_t main(){

    sync;

    int n, k; cin >> n >> k;
    if (k == 1 || k > 3) die(-1);
    if (k == 2) {
        cout << n - 1 << endl;
        for(int i = 1; i < n; i++) cout << i << ends << i + 1 << endl;
    }
    if (k == 3) {
        cout << 3 + (n - 4) * 2 << endl;
        for(int i = 1; i < 4; i++) cout << i << ends << i + 1 << endl;
        for(int i = 5; i < n; i++) cout << i << ends << 2 << endl;
        for(int i = 5; i < n; i++) cout << i << ends << 3 << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;

#define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (st                                  derr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<pii, int> mpii;
typedef set<int> sti;
const int INF = 1e9, MOD = /* INF + 7 */ INF - 1755647;
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
int power(int a, int b) { return (!b ? 1 : power(a, b / 2) * power(a, b / 2) * (b % 2 ? a : 1)); }
int mod(int a) { return (a % MOD + MOD) % MOD; }

/////////////////////////////////////////////////////////////////////

const int N = 2e5 + 20;

int32_t main(){

    sync;

    int n, k; cin >> n >> k;
    if (k == 2 && n > 4) {
        cout << n - 1 << endl;
        for(int i = 1; i < n; i++) cout << i << ends << i + 1 << endl;
    }
    else if (k == 3 && n > 3) {
        cout << 3 + (n - 4) * 2 << endl;
        for(int i = 1; i < 4; i++) cout << i << ends << i + 1 << endl;
        for(int i = 5; i <= n; i++) cout << 2 << ends << i << endl;
        for(int i = 5; i <= n; i++) cout << 3 << ends << i << endl;
    }
    else cout << -1 << endl;

    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;

#define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (st                                  derr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<pii, int> mpii;
typedef set<int> sti;
const int INF = 1e9, MOD = /* INF + 7 */ INF - 1755647;
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
int power(int a, int b) { return (!b ? 1 : power(a, b / 2) * power(a, b / 2) * (b % 2 ? a : 1)); }
int mod(int a) { return (a % MOD + MOD) % MOD; }

/////////////////////////////////////////////////////////////////////

const int N = 2e5 + 20;

int32_t main(){

    sync;

    int n, k; cin >> n >> k;
    if (k == 1 || k > 3) die(-1);
    if (k == 2) {
        cout << n - 1 << endl;
        for(int i = 1; i < n; i++) cout << i << ends << i + 1 << endl;
    }
    if (k == 3) {
        cout << 3 + (n - 4) * 2 << endl;
        for(int i = 1; i < 4; i++) cout << i << ends << i + 1 << endl;
        for(int i = 4; i < n; i++) cout << i << ends << 2 << endl;
        for(int i = 4; i < n; i++) cout << i << ends << 3 << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;

#define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (st                                  derr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<pii, int> mpii;
typedef set<int> sti;
const int INF = 1e9, MOD = /* INF + 7 */ INF - 1755647;
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
int power(int a, int b) { return (!b ? 1 : power(a, b / 2) * power(a, b / 2) * (b % 2 ? a : 1)); }
int mod(int a) { return (a % MOD + MOD) % MOD; }

/////////////////////////////////////////////////////////////////////

const int N = 2e5 + 20;

int32_t main(){

    sync;

    int n, k; cin >> n >> k;
    if (k == 1 || k > 3) die(-1);
    if (k == 2) {
        cout << n - 1 << endl;
        for(int i = 1; i < n; i++) cout << i << ends << i + 1 << endl;
    }
    if (k == 3) {
        cout << 3 + (n - 4) * 2 << endl;
        for(int i = 1; i < 4; i++) cout << i << ends << i + 1 << endl;
        for(int i = 5; i <= n; i++) cout << 2 << ends << i << endl;
        for(int i = 5; i <= n; i++) cout << 3 << ends << i << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;

#define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (st                                  derr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<pii, int> mpii;
typedef set<int> sti;
const int INF = 1e9, MOD = /* INF + 7 */ INF - 1755647;
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
int power(int a, int b) { return (!b ? 1 : power(a, b / 2) * power(a, b / 2) * (b % 2 ? a : 1)); }
int mod(int a) { return (a % MOD + MOD) % MOD; }

/////////////////////////////////////////////////////////////////////

const int N = 2e5 + 20;

int32_t main(){

    sync;

    int n, k; cin >> n >> k;
    if (k == 1 || k > 3) die(-1);
    if (k == 2) {
        cout << n - 1 << endl;
        for(int i = 1; i < n; i++) cout << i << ends << i + 1 << endl;
    }
    if (k == 3) {
        cout << 2 + (n - 4) * 2 << endl;
        cout << 1 << ends << 2 << endl;
        cout << n - 1 << ends << n << endl;
        for(int i = 3; i < n - 1; i++) cout << 2 << ends << i << endl;
        for(int i = 3; i < n - 1; i++) cout << n - 1 << ends << i << endl;
    }

    return 0;
}


//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, k;
    cin >> n >> k;
    if (k == 2)
    {
        if (n <= 4)
            cout << -1;
        else
        {
            cout << n - 1 << '\n';
            for (int i = 1; i <= n - 1; i ++)
                cout << i << ' ' << i + 1 << '\n';
        }
    }
    else if (k == 3)
    {
        if (n <= 3)
            cout << -1;
        else
        {
            cout << 3 * (n - 3) << '\n';
            for (int i = 1; i <= 3; i ++)
                cout << i << ' ' << i + 1 << '\n';
            for (int i = 5; i <= n; i ++)
                for (int j = 1; j <= 3; j ++)
                    cout << i << ' ' << j << '\n';
        }
    }
    else
        cout << -1;
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
long long const inf = 1e18;
int const mxn = 2e5+10;
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
int main(){
	int n,k;
	cin>>n>>k;
	if (k ==2 and n>=4 ){
		for (int i = 1;i<n;){
			cout<<i<<" "<<i+1<<"\n";
		}
		cout<<n<<" "<<1;
	}
	else if (k==3 and n>3){
		for (int i = 2 ;i<n;i++){
			cout<<1<<" "<<i<<"\n";
		}
		cout<<n<<" "<<n-1;
	}
	else
		cout<<-1;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
long long const inf = 1e18;
int const mxn = 2e5+10;
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
int main(){
	int n,k;
	cin>>n>>k;
	if (k ==2 and n>=4 ){
		cout<<n<<endl;
		for (int i = 1;i<n;i++){
			cout<<i<<" "<<i+1<<"\n";
		}
		cout<<n<<" "<<1;
	}
	else if (k==3 and n>3){
		cout<<n-1<<endl;
		for (int i = 2 ;i<n;i++){
			cout<<1<<" "<<i<<"\n";
		}
		cout<<n<<" "<<n-1;
	}
	else
		cout<<-1;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
long long const inf = 1e18;
int const mxn = 2e5+10;
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
int main(){
	int n,k;
	cin>>n>>k;
	if (k ==2 and n>=4 ){
		for (int i = 1;i<n;i++){
			cout<<i<<" "<<i+1<<"\n";
		}
		cout<<n<<" "<<1;
	}
	else if (k==3 and n>3){
		for (int i = 2 ;i<n;i++){
			cout<<1<<" "<<i<<"\n";
		}
		cout<<n<<" "<<n-1;
	}
	else
		cout<<-1;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
long long const inf = 1e18;
int const mxn = 2e5+10;
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
int main(){
	int n,k;
	cin>>n>>k;
	if (k ==2 and n>4 ){
		cout<<n<<endl;
		for (int i = 1;i<n;i++){
			cout<<i<<" "<<i+1<<"\n";
		}
		cout<<n<<" "<<1;
	}
	else if (k==3 and n>3){
		cout<<n-1<<endl;
		for (int i = 2 ;i<n;i++){
			cout<<1<<" "<<i<<"\n";
		}
		cout<<n<<" "<<n-1;
	}
	else
		cout<<-1;
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define Get(x,y) scanf("%I64d%I64d",&x,&y);
#define get(x) scanf("%I64d",&x);
#define Gett(x,y) scanf("%d%d",&x,&y);
#define gett(x) scanf("%d",&x);
#define f(i,a,b) for(int i=a;i<b;i++)
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl;
#define ll long long
#define pb push_back
#define maxm(a,b) a=max(a,b);
#define minm(a,b) a=min(a,b);
#define S second
#define F first
#define mp make_pair
int n,k;
int main(){
	cin>>n>>k;
	if(n<4 || k==1 || k>3) return cout<<-1,0;
	if(n==4){
		cout<<k<<endl;
		cout<<1<<" "<<2<<endl;
		cout<<2<<" "<<3<<endl;
		if(k==3)
			cout<<3<<" "<<4<<endl;
			return 0;
	}
	if(k==2){
		cout<<n<<endl;
		f(i,0,n)
			cout<<i+1<<" "<<(i+1)%n+1<<endl;
	}
	else{
		cout<<n-1<<endl;
		cout<<1<<" "<<2<<endl<<2<<" "<<3<<endl;
		f(i,4,n+1)
			cout<<3<<" "<<i<<endl;
	}
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define Get(x,y) scanf("%I64d%I64d",&x,&y);
#define get(x) scanf("%I64d",&x);
#define Gett(x,y) scanf("%d%d",&x,&y);
#define gett(x) scanf("%d",&x);
#define f(i,a,b) for(int i=a;i<b;i++)
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl;
#define ll long long
#define pb push_back
#define maxm(a,b) a=max(a,b);
#define minm(a,b) a=min(a,b);
#define S second
#define F first
#define mp make_pair
int n,k;
int main(){
	cin>>n>>k;
	if(n<4 || k==1 || k>3) return cout<<-1,0;
	if(n==4){
		cout<<1<<" "<<2<<endl;
		cout<<2<<" "<<3<<endl;
		if(k==3)
			cout<<cout<<3<<" "<<4<<endl;
			return 0;
	}
	if(k==2){
		f(i,0,n)
			cout<<i+1<<" "<<(i+1)%n+1<<endl;
	}
	else{
		cout<<1<<" "<<2<<endl;
		cout<<2<<" "<<3<<endl;
		cout<<1<<" "<<4<<endl;
		f(i,3,5){
			f(j,5,n)
				cout<<i<<" "<<j<<endl;
		}
	}
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define Get(x,y) scanf("%I64d%I64d",&x,&y);
#define get(x) scanf("%I64d",&x);
#define Gett(x,y) scanf("%d%d",&x,&y);
#define gett(x) scanf("%d",&x);
#define f(i,a,b) for(int i=a;i<b;i++)
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl;
#define ll long long
#define pb push_back
#define maxm(a,b) a=max(a,b);
#define minm(a,b) a=min(a,b);
#define S second
#define F first
#define mp make_pair
int n,k;
int main(){
	cin>>n>>k;
	if(n<4 || k==1 || k>3) return cout<<-1,0;
	if(n==4){
		cout<<1<<" "<<2<<endl;
		cout<<2<<" "<<3<<endl;
		if(k==3)
			cout<<3<<" "<<4<<endl;
			return 0;
	}
	if(k==2){
		f(i,0,n)
			cout<<i+1<<" "<<(i+1)%n+1<<endl;
	}
	else{
		cout<<1<<" "<<2<<endl;
		cout<<2<<" "<<3<<endl;
		cout<<1<<" "<<4<<endl;
		f(i,3,5){
			f(j,5,n)
				cout<<i<<" "<<j<<endl;
		}
	}
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define Get(x,y) scanf("%I64d%I64d",&x,&y);
#define get(x) scanf("%I64d",&x);
#define Gett(x,y) scanf("%d%d",&x,&y);
#define gett(x) scanf("%d",&x);
#define f(i,a,b) for(int i=a;i<b;i++)
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl;
#define ll long long
#define pb push_back
#define maxm(a,b) a=max(a,b);
#define minm(a,b) a=min(a,b);
#define S second
#define F first
#define mp make_pair
int n,k;
int main(){
	cin>>n>>k;
	if(n<4 || k==1 || k>3) return cout<<-1,0;
	if(n==4){
		cout<<k<<endl;
		cout<<1<<" "<<2<<endl;
		cout<<2<<" "<<3<<endl;
		if(k==3)
			cout<<3<<" "<<4<<endl;
			return 0;
	}
	if(k==2){
		cout<<n<<endl;
		f(i,0,n)
			cout<<i+1<<" "<<(i+1)%n+1<<endl;
	}
	else{
		cout<<3+2*(n-4)<<endl;
		cout<<1<<" "<<2<<endl;
		cout<<2<<" "<<3<<endl;
		cout<<1<<" "<<4<<endl;
		f(i,3,5){
			f(j,5,n+1)
				cout<<i<<" "<<j<<endl;
		}
	}
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define Get(x,y) scanf("%I64d%I64d",&x,&y);
#define get(x) scanf("%I64d",&x);
#define Gett(x,y) scanf("%d%d",&x,&y);
#define gett(x) scanf("%d",&x);
#define f(i,a,b) for(int i=a;i<b;i++)
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl;
#define ll long long
#define pb push_back
#define maxm(a,b) a=max(a,b);
#define minm(a,b) a=min(a,b);
#define S second
#define F first
#define mp make_pair
int n,k;
int main(){
	cin>>n>>k;
	if(n<4 || k==1 || k>3 || (k==2 && n==4)) return cout<<-1,0;
	if(n==4){
		cout<<k<<endl;
		cout<<1<<" "<<2<<endl;
		cout<<2<<" "<<3<<endl;
		cout<<3<<" "<<4<<endl;
		return 0;
	}
	if(k==2){
		cout<<n<<endl;
		f(i,0,n)
			cout<<i+1<<" "<<(i+1)%n+1<<endl;
	}
	else{
		cout<<n-1<<endl;
		cout<<1<<" "<<2<<endl<<2<<" "<<3<<endl;
		f(i,4,n+1)
			cout<<3<<" "<<i<<endl;
	}
}


///                ..:: In The Name Of God ::..
#include<bits/stdc++.h>

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define error(x) cerr << #x << " = " << (x) << endl;
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define Size(x) (int)(x).size()
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double ld;
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    if(k >= n or k > 3 or k <= 1 or n <= 3 or (k == 2 and n == 4))
        return cout << -1 << '\n', 0;
    if(k == 2) {
        cout << n -1 << '\n';
        for(int i = 0; i < n - 1; i++)
            cout << i + 1 << ' ' << i + 2 << '\n';
    }
    else if(k == 3) {
        cout << n - 1 << '\n';
        cout << 1 << ' ' << 2 << '\n';
        cout << 2 << ' ' << 3 << '\n';
        for(int i = 4; i <= n; i++)
            cout << 3 << ' ' << i << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

int n , k;

int main(){
    migmig
    cin >> n >> k;
    if(k!=2 and k!=3){
        cerr << "FUCK YOU!!!";
        dokme(-1);
    }
    if(k == 2){
        if(n <= 4){
            cerr << "FUCK YOU!!!";
            dokme(-1);
        }
        cout << n - 1 << endl;
        for (int i = 1;  i < n ; i ++){
            cout << i << ' ' << i + 1 << endl;
        }
    }
    if(k == 3){
        cout << n - 1 << endl;
        cout << 1 << ' ' << 2 << endl;
        for (int i = 3 ; i <= n ; i ++){
            cout << i << ' ' << 2 - (i % 2) << endl;
        }
    }
    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

int n , k;

int main(){
    migmig
    cin >> n >> k;
    if(k!=2 and k!=3){
        cerr << "FUCK YOU!!!";
        dokme(-1);
    }
    if(k == 2){
        cout << n - 1 << endl;
        for (int i = 1;  i < n ; i ++){
            cout << i << ' ' << i + 1 << endl;
        }
    }
    if(k == 3){
        cout << n - 1 << endl;
        cout << 1 << ' ' << 2 << endl;
        for (int i = 3 ; i <= n ; i ++){
            cout << i << ' ' << 2 - (i % 2) << endl;
        }
    }
    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

int n , k;

int main(){
    migmig
    cin >> n >> k;
    if(k!=2 ){
        cerr << "FUCK YOU!!!";
        dokme(-1);
    }
    if(k == 2){
        cout << n - 1 << endl;
        for (int i = 1;  i < n ; i ++){
            cout << i << ' ' << i + 1 << endl;
        }
    }
    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

int n , k;

int main(){
    migmig
    cin >> n >> k;
    if(k!=2 and k!=3){
        cerr << "FUCK YOU!!!";
        dokme(-1);
    }
    if(n < 4){
        dokme(-1);
    }
    if(k == 2){
        if(n <= 4){
            cerr << "FUCK YOU!!!";
            dokme(-1);
        }
        cout << n - 1 << endl;
        for (int i = 1;  i < n ; i ++){
            cout << i << ' ' << i + 1 << endl;
        }
    }
    if(k == 3){
        cout << n - 1 << endl;
        cout << 1 << ' ' << 2 << endl;
        for (int i = 3 ; i <= n ; i ++){
            cout << i << ' ' << 2 - (i % 2) << endl;
        }
    }
    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

int n , k;

int main(){
    migmig
    cin >> n >> k;
    if(k!=2 and k!=3){
        cerr << "FUCK YOU!!!";
        dokme(-1);
    }
    if(k == 2){
        if(n == 4){
            cerr << "FUCK YOU!!!";
            dokme(-1);
        }
        cout << n - 1 << endl;
        for (int i = 1;  i < n ; i ++){
            cout << i << ' ' << i + 1 << endl;
        }
    }
    if(k == 3){
        cout << n - 1 << endl;
        cout << 1 << ' ' << 2 << endl;
        for (int i = 3 ; i <= n ; i ++){
            cout << i << ' ' << 2 - (i % 2) << endl;
        }
    }
    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


#include <iostream>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    if (k > 3 || k == 1 || n < 4) return cout << -1, 0;
    if (k == 2) {
        if (n == 4) return cout << -1, 0;
        cout << n - 1 << '\n';
        for (int i = 1; i < n; ++i) cout << i << ' ' << i + 1 << '\n';
        return 0;
    }
    cout << n - 1 << "\n1 2\n2 3\n3 4\n";
    for (int i = 5; i <= n; ++i) cout << i << " 3\n";
}


# include <bits/stdc++.h>
using namespace std;

int n;
int k;

int main(){
    scanf("%d%d",&n,&k);
    if(k==1||k>=4) printf("-1\n");
    else {
        if(k==2){
            if(n<=4) printf("-1\n");
            else{
                printf("%d\n",n-1);
                for(int i=1;i<n;i++)
                    printf("%d %d\n",i,i+1);
            }
        }
        else{
            if(n<=3) printf("-1\n");
            else {
                printf("%d\n",n-1);
                for(int i=2;i<n;i++)
                    printf("1 %d\n",i);
                printf("%d %d\n",n-1,n);
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define fop(i,m,n) for(int i=m; i<n; i++)
#define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

using namespace std;

const long long MOD = 1000000007;
const long long N = 2e5;

void solve(){

    int n, k;
    cin >> n >> k;
    if(n<=3) cout << "-1";
    else if(n == 4){
      if(k == 3){
          cout << "3\n";
          fop(i,1,4) cout << i << " " << i+1 << endl;
      }
      else cout << "-1";
    }else{
      if(k==2){
          cout << n-1 << endl;
        fop(i,1,n) cout << i << " " << i+1 << endl;
      }else if(k == 3){
          cout << n-1 << endl;
        fop(i,2,n) cout << "1 " << i << endl;
        cout << n-1 << " " << n << endl;
      }else cout << "-1";
    }

}

int main()
{
    fastIO;

    int t=1;
    //cin >> t;
    while(t--) solve();

    return 0;
}


// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define hell 1000000007
#define narak 998244353
#define PI 3.14159265358979323844
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define endl "\n"
#define sqr(a) (a)*(a)
#define __lcm(m,n) m*(n/__gcd(m,n))
#define inputarr(a,n) for(int xxx=0;xxx<n;++xxx) cin>>(a)[xxx]
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define display(x) for(auto &a:x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define between(n,a,b) (a<=n&&n<=b)
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template<typename T, typename U> static inline void amin(T &x, U y) {
    if (y < x)
        x = y;
}

template<typename T, typename U> static inline void amax(T &x, U y) {
    if (x < y)
        x = y;
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& out, std::pair<T,U> a) {
    out<<a.fi<<" "<<a.se;
    return out;
}

template<typename T,typename U> std::istream& operator>>(std::istream& in, std::pair<T,U> &a) {
    in>>a.fi>>a.se;
    return in;
}

inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define pii std::pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<pii >
#define point complex<ll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

using namespace std;
using namespace __gnu_pbds;

void meowmeow321()
{
    int n,k;
    cin>>n>>k;
    if(k<2||k>3||n<=3){
        cout<<-1;
        return;
    }
    if(n==4&&k==2){
        cout<<-1;
        return;
    }
    if(k==2){
        // print line graph
        cout<<n-1<<endl;
        for (int i = 0; i < n-1; ++i) {
            cout<<i+1<<" "<<i+2<<endl;
        }
        return;
    }
    cout<<2*n-5<<endl;
    for (int i = 1; i <=3; ++i) {
        cout<<i<<" "<<i+1<<endl;
    }
    for (int i = 5; i <=n; ++i) {
        cout<<i<<" "<<2<<endl;
        cout<<i<<" "<<3<<endl;
    }

}
signed main()
{
    FAST;
    int testcases=1;
    //cin>>testcases;
    for(int i=0;i<testcases;++i)
    {
        meowmeow321();
    }
    cerr<<endl<<"Time Elasped : "<<elasped_time<<endl;
    return 0;
}


// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define hell 1000000007
#define narak 998244353
#define PI 3.14159265358979323844
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define endl "\n"
#define sqr(a) (a)*(a)
#define __lcm(m,n) m*(n/__gcd(m,n))
#define inputarr(a,n) for(int xxx=0;xxx<n;++xxx) cin>>(a)[xxx]
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define display(x) for(auto &a:x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define between(n,a,b) (a<=n&&n<=b)
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template<typename T, typename U> static inline void amin(T &x, U y) {
    if (y < x)
        x = y;
}

template<typename T, typename U> static inline void amax(T &x, U y) {
    if (x < y)
        x = y;
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& out, std::pair<T,U> a) {
    out<<a.fi<<" "<<a.se;
    return out;
}

template<typename T,typename U> std::istream& operator>>(std::istream& in, std::pair<T,U> &a) {
    in>>a.fi>>a.se;
    return in;
}

inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define pii std::pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<pii >
#define point complex<ll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

using namespace std;
using namespace __gnu_pbds;

void meowmeow321()
{
    int n,k;
    cin>>n>>k;
    if(k<2||k>3||n==3){
        cout<<-1;
        return;
    }
    if(n==4&&k==2){
        cout<<-1;
        return;
    }
    if(k==2){
        // print line graph
        cout<<n-1<<endl;
        for (int i = 0; i < n-1; ++i) {
            cout<<i+1<<" "<<i+2<<endl;
        }
        return;
    }
    cout<<2*n-5<<endl;
    for (int i = 1; i <=3; ++i) {
        cout<<i<<" "<<i+1<<endl;
    }
    for (int i = 5; i <=n; ++i) {
        cout<<i<<" "<<2<<endl;
        cout<<i<<" "<<3<<endl;
    }

}
signed main()
{
    FAST;
    int testcases=1;
    //cin>>testcases;
    for(int i=0;i<testcases;++i)
    {
        meowmeow321();
    }
    cerr<<endl<<"Time Elasped : "<<elasped_time<<endl;
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author parsa bahrami
 */

#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sz(x)                       (ll) x.size()
#define jjoin(x)                    for (auto i : x) cout << i << endl;
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define sep                         ' '
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define kill(x)                     return cout << x << endl , 0;
#define Hkill(x)                    cout << x << endl; exit(0);
#define endl                        '\n'

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 2e5 + 10;
const ll MAXA = 101;
const ll INF = 8e18;
const ll MOD = 998244353; //1e9 + 7
const ld PI = 4 * atan((ld) 1);

int main() {
    fast_io;
    set_random;
    ll n, k;
    cin >> n >> k;
    if (k <= 1 || k >= 4 || (k == 2 && n <= 3))
        kill(-1);
    cout << n - 1 << endl;
    if (k == 2) {
        for (ll i = 1; i <= n - 1; i++)
            cout << i << sep << i + 1 << endl;
    } else {
        cout << 1 << sep << 2 << endl;
        cout << 2 << sep << 3 << endl;
        for (ll i = 4; i <= n; i++) cout << 1 << sep << i << endl;
    }
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author parsa bahrami
 */

#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sz(x)                       (ll) x.size()
#define jjoin(x)                    for (auto i : x) cout << i << endl;
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define sep                         ' '
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define kill(x)                     return cout << x << endl , 0;
#define Hkill(x)                    cout << x << endl; exit(0);
#define endl                        '\n'

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 2e5 + 10;
const ll MAXA = 101;
const ll INF = 8e18;
const ll MOD = 998244353; //1e9 + 7
const ld PI = 4 * atan((ld) 1);

int main() {
    fast_io;
    set_random;
    ll n, k;
    cin >> n >> k;
    if (k <= 1 || k >= 4 || (k == 2 && n <= 4))
        kill(-1);
    cout << n - 1 << endl;
    if (k == 2) {
        for (ll i = 1; i <= n - 1; i++)
            cout << i << sep << i + 1 << endl;
    } else {
        cout << 1 << sep << 2 << endl;
        cout << 2 << sep << 3 << endl;
        for (ll i = 4; i <= n; i++) cout << 1 << sep << i << endl;
    }
    return 0;
}