#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <memory.h>
#include <algorithm>
#include <functional>
#include <numeric>
#include <sstream>
#include <iterator>
#include <stack>

#pragma comment(linker, "/STACK:5000000")

typedef long long LL;
#define mems(a, v) memset(a, v, sizeof(a))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define len(s) (s).length()
#define fori(n) for(int (i)=0; (i)<n; (i)++)
using namespace std;
map<char, int > a, b, c;
string s, ans = "";

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> s;
	int n = s.length();
	for (int i = 0; i < n; ++i) {
		a[s[i]]++;
	}

	for (auto it = a.begin(); it != a.end(); ++it) {
		if (it->second % 2 == 1) {
			b[it->first] = it->second;
		}
		else
		{
			c[it->first] = it->second;
		}
	}

	int k = 1;

	for (auto it = b.begin(); it != b.end(); ++it) {
		if (k <= b.size() / 2) {
			it->second++;
		}
		else {
			if (n%2 == 1 && k == b.size()/2+1) {
			}
			else {
				it->second--;
			}
		}
		k++;
	}

	string t = "";
	int p = 0;
	for (auto it = b.begin(); it != b.end(); ++it) {
		if (it->second % 2 == 0 && it->second > 0) c[it->first] = it->second;
		else {
			c[it->first] = it->second-1;
			t = it->first;
		}
	}

	for (auto it = c.begin(); it != c.end(); ++it) {
		for (int i = 0; i < it->second / 2; ++i) {
			ans += it->first;
		}
	}

	cout << ans << t;
	reverse(ans.begin(), ans.end());
	cout << ans;

	return 0;

}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>

#define FOR(i,a,n) for(int i = a; i < n; i++)
#define MAX 10010

using namespace std;

struct node {
    int v, dist, ed;
    bool operator < (const node &e) const {
        if(dist > e.dist) return true;
        if(dist == e.dist && ed > e.ed) return true;
        return false;
    }
};

vector<node> cst;
priority_queue<node> Q;
vector<int> adj[MAX];

bool cmp_cst(node a, node b){
    if(a.dist <= b.dist) return true;
    return false;
}

void print_graph(int n){
    FOR(i,0,n+1){
        FOR(j,0,adj[i].size()) {
            cout << i << " " << adj[i][j] << endl;
        }
    }
}

void print_graph2(int n){
    FOR(i,0,n+1){
        cout << "I: " << i << ": ";
        FOR(j,0,adj[i].size()) {
            cout << adj[i][j] << " ";
        }
        cout << endl;
    }
}

int main(){
    int n, k;
    cin >> n >> k;

    FOR(i,0,n){
        node no;
        no.v = i+1;
        int a;
        cin >> a;
        no.dist = a;
        no.ed = 0;
        cst.push_back(no);
    }

    sort(cst.begin(), cst.end(), cmp_cst);

    /*FOR(i,0,n) {
        cout << cst[i].v << "(" << cst[i].dist << ")\n";
    }
    cout << endl;*/

    node w = cst[0];
    if(w.dist > 0 || (n > 1 && cst[1].dist == 0)) {
        cout << -1 << endl;
        return 0;
    }
    Q.push(w);
    int i = 1, cnt = 0;
    while(!Q.empty()){
        if(i > n) break;
        w = Q.top();
        Q.pop();
        //cout << "popei o vertice " << w.v << " dist: " << w.dist << " arestas: " << w.ed << endl;

        while(cst[i].dist == w.dist + 1 && w.ed <= k){
            if(i > n) break;
            node w0 = cst[i];
            // cout << "considerando o vertice " << w0.v << endl;
            adj[w.v].push_back(w0.v);
            w.ed++;
            cnt++;
            if(w.ed > k) {
                cout << -1 << endl;
                return 0;
            }
            Q.push(w0);
            i++;
        }

    }
    if(i < n) {
        cout << -1 << endl;
        return 0;
    } else {
        cout << cnt << endl;
        print_graph(n);
    }

    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>

#define FOR(i,a,n) for(int i = a; i < n; i++)
#define MAX 10010

using namespace std;

struct node {
    int v, dist, ed;
    bool operator < (const node &e) const {
        if(dist > e.dist) return true;
        if(dist == e.dist && ed > e.ed) return true;
        return false;
    }
};

vector<node> cst;
priority_queue<node> Q;
vector<int> adj[MAX];

bool cmp_cst(node a, node b){
    if(a.dist <= b.dist) return true;
    return false;
}

void print_graph(int n){
    FOR(i,0,n+1){
        FOR(j,0,adj[i].size()) {
            cout << i << " " << adj[i][j] << endl;
        }
    }
}

void print_graph2(int n){
    FOR(i,0,n+1){
        cout << "I: " << i << ": ";
        FOR(j,0,adj[i].size()) {
            cout << adj[i][j] << " ";
        }
        cout << endl;
    }
}

int main(){
    int n, k;
    cin >> n >> k;

    FOR(i,0,n){
        node no;
        no.v = i+1;
        int a;
        cin >> a;
        no.dist = a;
        no.ed = 0;
        cst.push_back(no);
    }

    sort(cst.begin(), cst.end(), cmp_cst);

    node v = cst[0];
    if(n > 1 && cst[1].dist == 0){
        cout << -1 << endl;
        return 0;
    }

    int i = 0, j = 1, cnt = 0;
    while(i < n){
        if(j == n) break;
        node w = cst[i];

        if(w.dist >= cst[j].dist) {
            cout << -1 << endl;
            return 0;
        }
        while((w.dist +1 == cst[j].dist) && w.ed < k) {
            node w0 = cst[j];
            /*
            cout << "I: " << i << " J: " << j << endl;
            cout << "considerando vertice " << w.v << " dist: " << w.dist << " ed: " << w.ed << endl;
            cout << "--- considerando vertice " << w0.v << " dist: " << w0.dist << " ed: " << w0.ed << endl;
            */
            adj[w.v].push_back(w0.v);
            w.ed++;
            cst[j].ed++;
            j++;
            cnt++;
            if(j == n) break;
        }
        i++;
    }
    cout << cnt << endl;
    print_graph(n);

    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>

#define FOR(i,a,n) for(int i = a; i < n; i++)
#define MAX 10010

using namespace std;

struct node {
    int v, dist, ed;
    bool operator < (const node &e) const {
        if(dist > e.dist) return true;
        if(dist == e.dist && ed > e.ed) return true;
        return false;
    }
};

vector<node> cst;
priority_queue<node> Q;
vector<int> adj[MAX];

bool cmp_cst(node a, node b){
    if(a.dist <= b.dist) return true;
    return false;
}

void print_graph(int n){
    FOR(i,0,n+1){
        FOR(j,0,adj[i].size()) {
            cout << i << " " << adj[i][j] << endl;
        }
    }
}

void print_graph2(int n){
    FOR(i,0,n+1){
        cout << "I: " << i << ": ";
        FOR(j,0,adj[i].size()) {
            cout << adj[i][j] << " ";
        }
        cout << endl;
    }
}

int main(){
    int n, k;
    cin >> n >> k;

    FOR(i,0,n){
        node no;
        no.v = i+1;
        int a;
        cin >> a;
        no.dist = a;
        no.ed = 0;
        cst.push_back(no);
    }

    sort(cst.begin(), cst.end(), cmp_cst);

    /*FOR(i,0,n) {
        cout << cst[i].v << "(" << cst[i].dist << ")\n";
    }
    cout << endl;*/

    node w = cst[0];
    if(w.dist > 0 || (n > 1 && cst[1].dist == 0)) {
        cout << -1 << endl;
        return 0;
    }
    Q.push(w);
    int i = 1, cnt = 0;
    while(!Q.empty()){
        w = Q.top();
        Q.pop();

        //cout << "popei o vertice " << w.v << " dist: " << w.dist << " arestas: " << w.ed << endl;

        if(cst[i].dist == w.dist + 1){
            node w0 = cst[i];

            // cout << "considerando o vertice " << w0.v << endl;

            adj[w.v].push_back(w0.v);
            w.ed++;
            cnt++;
            if(w.ed > k) {
                cout << -1 << endl;
                return 0;
            }
            Q.push(w);
            Q.push(w0);
            i++;
        }

    }
    if(i < n) {
        cout << -1 << endl;
        return 0;
    } else {
        cout << cnt << endl;
        print_graph(n);
    }

    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>

#define FOR(i,a,n) for(int i = a; i < n; i++)
#define MAX 10010

using namespace std;

struct node {
    int v, dist, ed;
    bool operator < (const node &e) const {
        if(dist > e.dist) return true;
        if(dist == e.dist && ed > e.ed) return true;
        return false;
    }
};

vector<node> cst;
priority_queue<node> Q;
vector<int> adj[MAX];

bool cmp_cst(node a, node b){
    if(a.dist <= b.dist) return true;
    return false;
}

void print_graph(int n){
    FOR(i,0,n+1){
        FOR(j,0,adj[i].size()) {
            cout << i << " " << adj[i][j] << endl;
        }
    }
}

void print_graph2(int n){
    FOR(i,0,n+1){
        cout << "I: " << i << ": ";
        FOR(j,0,adj[i].size()) {
            cout << adj[i][j] << " ";
        }
        cout << endl;
    }
}

int main(){
    int n, k;
    cin >> n >> k;

    FOR(i,0,n){
        node no;
        no.v = i+1;
        int a;
        cin >> a;
        no.dist = a;
        no.ed = 0;
        cst.push_back(no);
    }

    sort(cst.begin(), cst.end(), cmp_cst);

    /*FOR(i,0,n) {
        cout << cst[i].v << "(" << cst[i].dist << ")\n";
    }
    cout << endl;*/

    node w = cst[0];
    if(w.dist > 0 || (n > 1 && cst[1].dist == 0)) {
        cout << -1 << endl;
        return 0;
    }
    Q.push(w);
    int i = 1, cnt = 0, bla = 1;
    while(!Q.empty()){
        if(i >= n) break;
        w = Q.top();
        Q.pop();
        //cout << "popei o vertice " << w.v << " dist: " << w.dist << " arestas: " << w.ed << endl;
        if(cst[i].dist == w.dist + 1) {
            cout << -1 << endl;
           return 0;
        }
        while(cst[i].dist == w.dist + 1 && w.ed < k){
            if(i >= n) break;
            node w0 = cst[i];
            // cout << "considerando o vertice " << w0.v << endl;
            adj[w.v].push_back(w0.v);
            w.ed++;
            cnt++;
            if(w.ed > k) {
                cout << -1 << endl;
                return 0;
            }
            Q.push(w0);
            i++;
        }

    }
    if(i < n) {
        cout << -1 << endl;
        return 0;
    } else {
        cout << cnt << endl;
        print_graph(n);
    }

    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>

#define FOR(i,a,n) for(int i = a; i < n; i++)
#define MAX 100100

using namespace std;

vector<pair<int, int> >p;
vector<pair<int,int> > cst;
int edges[MAX];
int c[MAX];

void swap(int a, int b){
    pair<int, int> tmp = cst[a];
    cst[a] = cst[b];
    cst[b] = tmp;
}

void quicksort(int lo, int hi){
    if(hi <= lo) return;
    int lt = lo, gt = hi;
    pair<int, int> v = cst[lo];
    int i = lo;
    while(i <= gt){
        if(cst[i].first < v.first) swap(lt++, i++);
        else if(cst[i].first > v.first) swap(i, gt--);
        else i++;
    }
    quicksort(lo, lt-1);
    quicksort(gt+1, hi);
}

bool cmp_cst(pair<int, int> a, pair<int, int> b){
    if(a.first <= b.first) return true;
    return false;
}

void print_graph(int n){
    FOR(i,0,p.size()){
        cout << p[i].first << " " << p[i].second << endl;
    }
}

int main(){
    int n, k;
    cin >> n >> k;

    FOR(i,0,n){
        pair<int, int> p2;
        p2.second = i+1;
        int a;
        cin >> a;
        p2.first = a;
        cst.push_back(p2);
        edges[i+1] = 0;
    }

    quicksort(0,cst.size()-1);

    pair<int, int> v = cst[0];
    if(n > 1 && cst[1].first == 0){
        cout << -1 << endl;
        return 0;
    }

    int i = 0, j = 1, cnt = 0;
    while(i < n){
        if(j == n) break;
        pair<int,int> w = cst[i];

        if(w.first >= cst[j].first) {
            cout << -1 << endl;
            return 0;
        }
        while((w.first + 1 == cst[j].first) && edges[w.second] < k) {
            pair<int, int> w0 = cst[j];
            p.push_back(make_pair(w.second, w0.second));
            edges[w.second]++;
            edges[cst[j].second]++;
            j++;
            cnt++;
            if(j == n) break;
        }
        i++;
    }
    cout << cnt << endl;
    print_graph(n);

    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>

#define FOR(i,a,n) for(int i = a; i < n; i++)
#define MAX 10010

using namespace std;

vector<pair<int, int> >p;
vector<pair<int,int> > cst;
int edges[MAX];

bool cmp_cst(pair<int, int> a, pair<int, int> b){
    if(a.first <= b.first) return true;
    return false;
}

void print_graph(int n){
    FOR(i,0,p.size()){
        cout << p[i].first << " " << p[i].second << endl;
    }
}

int main(){
    int n, k;
    cin >> n >> k;

    FOR(i,0,n){
        pair<int, int> p2;
        p2.second = i+1;
        int a;
        cin >> a;
        p2.first = a;
        cst.push_back(p2);
        edges[i] = 0;
    }

    sort(cst.begin(), cst.end(), cmp_cst);

    pair<int, int> v = cst[0];
    if(n > 1 && cst[1].first == 0){
        cout << -1 << endl;
        return 0;
    }

    int i = 0, j = 1, cnt = 0;
    while(i < n){
        if(j == n) break;
        pair<int,int> w = cst[i];

        if(w.first >= cst[j].first) {
            cout << -1 << endl;
            return 0;
        }
        while((w.first + 1 == cst[j].first) && edges[w.second] < k) {
            pair<int, int> w0 = cst[j];
            /*
            cout << "I: " << i << " J: " << j << endl;
            cout << "considerando vertice " << w.v << " dist: " << w.dist << " ed: " << w.ed << endl;
            cout << "--- considerando vertice " << w0.v << " dist: " << w0.dist << " ed: " << w0.ed << endl;
            */
            p.push_back(make_pair(w.second, w0.second));
            edges[w.second]++;
            edges[cst[j].second]++;
            j++;
            cnt++;
            if(j == n) break;
        }
        i++;
    }
    cout << cnt << endl;
    print_graph(n);

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
const int N=200110;
pair<int,int>pa;
vector<int>G[N];
vector<pair<int,int> >ans;
void init(){
    for(int i=0;i<200110;i++) G[i].clear();
    ans.clear();
}
long long    min(long long a,long long b){
    return a<=b?a:b;
}
int main(){
    int n,m,a,i,j,flag;
    while(scanf("%d%d",&n,&m)!=EOF){
        flag=0;
        init();
        for(i=1;i<=n;i++){
            scanf("%d",&a);
             G[a].push_back(i);
        }
        for(i=0;i<=100015;i++){
            if(G[i].size()*1LL*m<G[i+1].size()||G[0].size()!=1){
                puts("-1");
                flag=1;
                //printf("%d\n",i);
                break;
            }
            for(j=0;j<G[i].size();j++){
                long long len=G[i+1].size();
                for(long long k=j*m*1ll;k<min(len,(long long)(j+1)*1LL*m);k++){
                    pa.first=G[i][j];
                    pa.second=G[i+1][k];
                    ans.push_back(pa);
                }
            }
            if(i==0) m--;
        }
        if(!flag){
            cout<<ans.size()<<endl;
            for(i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
        }
    }
}


#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
const int N=200110;
pair<int,int>pa;
vector<int>G[N];
vector<pair<int,int> >ans;
void init(){
    for(int i=0;i<=200110;i++) G[i].clear();
    ans.clear();
}
long long    min(long long a,long long b){
    return a<=b?a:b;
}
int main(){
    int n,m,a,i,j,flag;
    while(scanf("%d%d",&n,&m)!=EOF){
        flag=0;
        init();
        for(i=1;i<=n;i++){
            scanf("%d",&a);
             G[a].push_back(i);
        }
        for(i=0;i<=100015;i++){
            if((long long)G[i].size()*1ll*m<(long long)G[i+1].size()||G[0].size()!=1){
                puts("-1");
                flag=1;
                //printf("%d\n",i);
                break;
            }
            for(j=0;j<G[i].size();j++){
                long long len=G[i+1].size();
                for(long long k=j*m*1ll;k<min(len,(long long)(j+1)*1ll*m);k++){
                    pa.first=G[i][j];
                    pa.second=G[i+1][k];
                    ans.push_back(pa);
                }
            }
            if(i==0) m--;
        }
        if(!flag){
            cout<<ans.size()<<endl;
            for(i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
        }
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int N=100010;
int f[N],vis[N];
vector<int>G[N];
int n,m,sum,u;
void dfs(int v,int len){
	if(v>n||len>n) return ;
//	printf("adsafdaa\n");
	for(int i=1;i<=n;i++) if(!vis[i]&&f[i]==len){
		if(v!=u&&G[v].size()>=m-1||u==v&&G[v].size()>=m) continue;
		G[v].push_back(i);
		vis[i]=1;
		sum++;
		dfs(i,len+1);
	}
	return ;
}
void init(){
	for(int i=0;i<N;i++) G[i].clear();
	memset(vis,0,sizeof(vis));
}
int main(){
	int i,j,flag;
	while(scanf("%d%d",&n,&m)!=EOF){
		flag=0;
		sum=0;
		init();
		for(i=1;i<=n;i++){
			scanf("%d",&f[i]);
			if(f[i]==0) u=i;
		}
		vis[u]=1;
		dfs(u,1);
		for(i=1;i<=n;i++) if(!vis[i]){
			flag=1;
			//printf("%d\n",i);
			break;
		}
		if(flag||sum==0) printf("-1\n");
		else {
			printf("%d\n",sum);
			for(i=1;i<=n;i++)
				for(j=0;j<G[i].size();j++) printf("%d %d\n",i,G[i][j]);
		}
	}
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
const int N=200110;
pair<int,int>pa;
vector<int>G[N];
vector<pair<int,int> >ans;
void init(){
    for(int i=0;i<200110;i++) G[i].clear();
    ans.clear();
}
long long    min(long long a,long long b){
    return a<=b?a:b;
}
int main(){
    int n,m,a,i,j,flag;
    while(scanf("%d%d",&n,&m)!=EOF){
        flag=0;
        init();
        for(i=1;i<=n;i++){
            scanf("%d",&a);
             G[a].push_back(i);
        }
        for(i=0;i<=100015;i++){
            if(G[i].size()*1LL*m<G[i+1].size()||G[0].size()!=1){
                puts("-1");
                flag=1;
                //printf("%d\n",i);
                break;
            }
            for(j=0;j<G[i].size();j++){
                long long len=G[i+1].size();
                for(long long k=1LL*j*m;k<min(len,(long long)(j+1)*1LL*m);k++){
                    pa.first=G[i][j];
                    pa.second=G[i+1][k];
                    ans.push_back(pa);
                }
            }
            if(i==0) m--;
        }
        if(!flag){
            cout<<ans.size()<<endl;
            for(i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
        }
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
const int N=1000010;
int f[N],vis[N];
vector<int>G[N];
int n,m,flag,sum;
struct node{
	int u;
	int len;
};
queue<node>qu;
void init(){
	while(!qu.empty()) qu.pop();
	for(int i=0;i<N;i++) G[i].clear();
}
void bfs(int u,int len){
	node beg;
	beg.u=u;
	beg.len=len;
	qu.push(beg);
	while(!qu.empty()){
		node en=qu.front();
		node end=en;
		while(en.len<=len&&!qu.empty()){
			qu.pop();
			en=qu.front();
		}
		for(int i=1;i<=n;i++) if(f[i]==len){
			node mid;
			mid.u=i;
			mid.len=len+1;
			qu.push(mid);
			G[end.u].push_back(i);
			sum++;
		}
		if(G[end.u].size()>m){
			flag=1;
			break;
		}
		len++;
	}
}
int main(){
	int u;
	while(scanf("%d%d",&n,&m)!=EOF){
		init();
		for(int i=1;i<=n;i++){
			scanf("%d",&f[i]);
			if(f[i]==0) u=i;
		}
		flag=0;
		sum=0;
		bfs(u,1);

		if(flag||sum==0) printf("-1\n");
		else{
			printf("%d\n",sum);
			for(int i=1;i<=n;i++)
				for(int j=0;j<G[i].size();j++) printf("%d %d\n",i,G[i][j]);
		}
	}

}
/*
7 3
2 2 0 1 3 2 1
6
1 7
2 7
3 4
3 7
4 6
5 6

*/


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int N=100010;
int f[N],vis[N];
vector<int>G[N];
int n,m,sum;
void dfs(int u,int len){
	if(u>n||len>n) return ;
//	printf("adsafdaa\n");
	for(int i=1;i<=n;i++) if(!vis[i]&&f[i]==len&&G[u].size()<m){
		G[u].push_back(i);
		vis[i]=1;
		sum++;
		dfs(i,len+1);
	}
	return ;
}
void init(){
	for(int i=0;i<N;i++) G[i].clear();
	memset(vis,0,sizeof(vis));
}
int main(){
	int u,i,j,flag;
	while(scanf("%d%d",&n,&m)!=EOF){
		flag=0;
		sum=0;
		init();
		for(i=1;i<=n;i++){
			scanf("%d",&f[i]);
			if(f[i]==0) u=i;
		}
		vis[u]=1;
		dfs(u,1);
		for(i=1;i<=n;i++) if(!vis[i]){
			flag=1;
			//printf("%d\n",i);
			break;
		}
		if(flag||sum==0) printf("-1\n");
		else {
			printf("%d\n",sum);
			for(i=1;i<=n;i++)
				for(j=0;j<G[i].size();j++) printf("%d %d\n",i,G[i][j]);
		}
	}
}


#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
const int N=200110;
pair<int,int>pa;
vector<int>G[N];
vector<pair<int,int> >ans;
void init(){
    for(int i=0;i<=100110;i++) G[i].clear();
    ans.clear();
}
__int64  min(__int64 a,__int64 b){
    return a<=b?a:b;
}
int main(){
    int n,m,a,i,j,flag;
    while(scanf("%d%d",&n,&m)!=EOF){
        flag=0;
        init();
        for(i=1;i<=n;i++){
            scanf("%d",&a);
             G[a].push_back(i);
        }
        for(i=0;i<=100005;i++){
            if(G[i].size()*m<G[i+1].size()||G[0].size()!=1){
                puts("-1");
                flag=1;
                //printf("%d\n",i);
                break;
            }
            for(j=0;j<G[i].size();j++){
                __int64 len=G[i+1].size();
                for(__int64 k=j*m;k<min(len,(__int64)(j+1)*m);k++){
                    pa.first=G[i][j];
                    pa.second=G[i+1][k];
                    ans.push_back(pa);
                }
            }
            if(i==0) m--;
        }
        if(!flag){
            printf("%d\n",ans.size());
            for(i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
        }
    }
}


#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
const int N=200110;
pair<int,int>pa;
vector<int>G[N];
vector<pair<int,int> >ans;
void init(){
    for(int i=0;i<=100110;i++) G[i].clear();
    ans.clear();
}
int main(){
    int n,m,a,i,j,k,flag;
    while(scanf("%d%d",&n,&m)!=EOF){
        flag=0;
        init();
        for(i=1;i<=n;i++){
            scanf("%d",&a);
             G[a].push_back(i);
        }
        for(i=0;i<=100005;i++){
            if(G[i].size()*m<G[i+1].size()||G[0].size()!=1){
                puts("-1");
                flag=1;
                //printf("%d\n",i);
                break;
            }
            for(j=0;j<G[i].size();j++){
                int len=G[i+1].size();
                for(k=j*m;k<min(len,(j+1)*m);k++){
                    pa.first=G[i][j];
                    pa.second=G[i+1][k];
                    ans.push_back(pa);
                }
            }
            if(i==0) m--;
        }
        if(!flag){
            printf("%d\n",ans.size());
            for(i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
        }
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
const int N=1000010;
int f[N],vis[N];
vector<int>G[N];
int n,m,flag,sum;
struct node{
	int u;
	int len;
};
queue<node>qu;
void init(){
	while(!qu.empty()) qu.pop();
	for(int i=0;i<N;i++) G[i].clear();
}
void bfs(int u,int len){
	node beg;
	beg.u=u;
	beg.len=len;
	qu.push(beg);
	while(!qu.empty()){
		node en=qu.front();
		node end=en;
		while(en.len<=len){
			qu.pop();
			en=qu.front();
		}
		for(int i=1;i<=n;i++) if(f[i]==len){
			node mid;
			mid.u=i;
			mid.len=len+1;
			qu.push(mid);
			G[end.u].push_back(i);
			sum++;
		}
		if(G[end.u].size()>m){
			flag=1;
			break;
		}
		len++;
	}
}
int main(){
	int u;
	while(scanf("%d%d",&n,&m)!=EOF){
		init();
		for(int i=1;i<=n;i++){
			scanf("%d",&f[i]);
			if(f[i]==0) u=i;
		}
		flag=0;
		sum=0;
		bfs(u,1);

		if(flag||sum==0) printf("-1\n");
		else {
			printf("%d\n",sum);
			for(int i=1;i<=n;i++)
				for(int j=0;j<G[i].size();j++) printf("%d %d\n",i,G[i][j]);
		}
	}

}
/*
7 3
2 2 0 1 3 2 1
6
1 7
2 7
3 4
3 7
4 6
5 6

*/


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
const int N=200110;
pair<int,int>pa;
vector<int>G[N];
vector<pair<int,int> >ans;
void init(){
    for(int i=0;i<=200110;i++) G[i].clear();
    ans.clear();
}
long long    min(long long a,long long b){
    return a<=b?a:b;
}
int main(){
    int n,m,a,i,j,flag;
    while(scanf("%d%d",&n,&m)!=EOF){
        flag=0;
        init();
        for(i=1;i<=n;i++){
            scanf("%d",&a);
             G[a].push_back(i);
        }
        for(i=0;i<=100015;i++){
            if((long long)G[i].size()*1ll*m<(long long)G[i+1].size()||G[0].size()!=1){
                puts("-1");
                flag=1;
                //printf("%d\n",i);
                break;
            }
            for(j=0;j<G[i].size();j++){
                long long len=G[i+1].size();
                for(long long k=j*m*1ll;k<min(len,(long long)(j+1)*1ll*m);k++){
                    pa.first=G[i][j];
                    pa.second=G[i+1][k];
                    ans.push_back(pa);
                }
            }
            if(i==0) m--;
        }
        if(!flag){
            cout<<ans.size()<<endl;
            for(i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
        }
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
const int N=200110;
pair<int,int>pa;
vector<int>G[N];
vector<pair<int,int> >ans;
void init(){
    for(int i=0;i<200110;i++) G[i].clear();
    ans.clear();
}
long long    min(long long a,long long b){
    return a<=b?a:b;
}
int main(){
    int n,m,a,i,j,flag;
    while(scanf("%d%d",&n,&m)!=EOF){
        flag=0;
        init();
        for(i=1;i<=n;i++){
            scanf("%d",&a);
             G[a].push_back(i);
        }
        for(i=0;i<=100015;i++){
            if(G[i].size()*1LL*m<G[i+1].size()||G[0].size()!=1){
                puts("-1");
                flag=1;
                //printf("%d\n",i);
                break;
            }
            for(j=0;j<G[i].size();j++){
                long long len=G[i+1].size();
                for(long long k=j*m*1LL;k<min(len,(long long)(j+1)*1LL*m);k++){
                    pa.first=G[i][j];
                    pa.second=G[i+1][k];
                    ans.push_back(pa);
                }
            }
            if(i==0) m--;
        }
        if(!flag){
            cout<<ans.size()<<endl;
            for(i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
        }
    }
}


#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
const int N=200110;
pair<int,int>pa;
vector<int>G[N];
vector<pair<int,int> >ans;
void init(){
    for(int i=0;i<=200110;i++) G[i].clear();
    ans.clear();
}
__int64  min(__int64 a,__int64 b){
    return a<=b?a:b;
}
int main(){
    int n,m,a,i,j,flag;
    while(scanf("%d%d",&n,&m)!=EOF){
        flag=0;
        init();
        for(i=1;i<=n;i++){
            scanf("%d",&a);
             G[a].push_back(i);
        }
        for(i=0;i<=100015;i++){
            if((__int64)G[i].size()*m<(__int64)G[i+1].size()||G[0].size()!=1){
                puts("-1");
                flag=1;
                //printf("%d\n",i);
                break;
            }
            for(j=0;j<G[i].size();j++){
                __int64 len=G[i+1].size();
                for(__int64 k=j*m;k<min(len,(__int64)(j+1)*m);k++){
                    pa.first=G[i][j];
                    pa.second=G[i+1][k];
                    ans.push_back(pa);
                }
            }
            if(i==0) m--;
        }
        if(!flag){
            printf("%I64d\n",(__int64)ans.size());
            for(i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
        }
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
const int N=1000010;
int f[N],vis[N];
vector<int>G[N];
queue<int>qu;
struct node{
	int u;
	int len;
};
int n,m,flag,sum;
void init(){
	while(!qu.empty()) qu.pop();
	for(int i=0;i<N;i++) G[i].clear();
}
void bfs(int u,int len){
	qu.push(u);
	while(!qu.empty()){
		int v=qu.front();
		qu.pop();
		for(int i=1;i<=n;i++) if(f[i]==len){
			qu.push(i);
			G[v].push_back(i);
			sum++;
		}
		if(G[v].size()>m){
			flag=1;
			break;
		}
		len++;
	}
}
int main(){
	int u;
	while(scanf("%d%d",&n,&m)!=EOF){
		init();
		for(int i=1;i<=n;i++){
			scanf("%d",&f[i]);
			if(f[i]==0) u=i;
		}
		flag=0;
		sum=0;
		bfs(u,1);

		if(flag||sum==0) printf("-1\n");
		else {
			printf("%d\n",sum);
			for(int i=1;i<=n;i++)
				for(int j=0;j<G[i].size();j++) printf("%d %d\n",i,G[i][j]);
		}
	}

}


#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
const int N=200110;
pair<int,int>pa;
vector<int>G[N];
vector<pair<int,int> >ans;
void init(){
    for(int i=0;i<=100110;i++) G[i].clear();
    ans.clear();
}
__int64  min(__int64 a,__int64 b){
    return a<=b?a:b;
}
int main(){
    int n,m,a,i,j,flag;
    while(scanf("%d%d",&n,&m)!=EOF){
        flag=0;
        init();
        for(i=1;i<=n;i++){
            scanf("%d",&a);
             G[a].push_back(i);
        }
        for(i=0;i<=100005;i++){
            if((__int64)G[i].size()*m<(__int64)G[i+1].size()||G[0].size()!=1){
                puts("-1");
                flag=1;
                //printf("%d\n",i);
                break;
            }
            for(j=0;j<G[i].size();j++){
                __int64 len=G[i+1].size();
                for(__int64 k=j*m;k<min(len,(__int64)(j+1)*m);k++){
                    pa.first=G[i][j];
                    pa.second=G[i+1][k];
                    ans.push_back(pa);
                }
            }
            if(i==0) m--;
        }
        if(!flag){
            printf("%d\n",ans.size());
            for(i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
        }
    }
}


#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
const int N=100011;
pair<int,int>pa;
vector<int>G[N];
vector<pair<int,int> >ans;
void init(){
    for(int i=0;i<=100010;i++) G[i].clear();
    ans.clear();
}
int main(){
    int n,m,a,i,j,k,flag;
    while(scanf("%d%d",&n,&m)!=EOF){
        flag=0;
        init();
        for(i=1;i<=n;i++){
            scanf("%d",&a);
             G[a].push_back(i);
        }
        for(i=0;i<=100005;i++){
            if(G[i].size()*m<G[i+1].size()||G[0].size()!=1){
                puts("-1");
                flag=1;
                //printf("%d\n",i);
                break;
            }
            for(j=0;j<G[i].size();j++){
                int len=G[i+1].size();
                for(k=j*m;k<min(len,(j+1)*m);k++){
                    pa.first=G[i][j];
                    pa.second=G[i+1][k];
                    ans.push_back(pa);
                }
            }

            if(i==0) m--;
        }
        if(!flag){
            printf("%d\n",ans.size());
            for(i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
        }
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
const int N=200110;
pair<int,int>pa;
vector<int>G[N];
vector<pair<int,int> >ans;
void init(){
    for(int i=0;i<200110;i++) G[i].clear();
    ans.clear();
}
long long    min(long long a,long long b){
    return a<=b?a:b;
}
int main(){
    int n,m,a,i,j,flag;
    while(scanf("%d%d",&n,&m)!=EOF){
        flag=0;
        init();
        for(i=1;i<=n;i++){
            scanf("%d",&a);
             G[a].push_back(i);
        }
        for(i=0;i<=100015;i++){
            if((long long)G[i].size()*1ll*m<(long long)G[i+1].size()||G[0].size()!=1){
                puts("-1");
                flag=1;
                //printf("%d\n",i);
                break;
            }
            for(j=0;j<G[i].size();j++){
                long long len=G[i+1].size();
                for(long long k=j*m*1ll;k<min(len,(long long)(j+1)*1ll*m);k++){
                    pa.first=G[i][j];
                    pa.second=G[i+1][k];
                    ans.push_back(pa);
                }
            }
            if(i==0) m--;
        }
        if(!flag){
            cout<<ans.size()<<endl;
            for(i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
        }
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int N=100010;
int f[N],vis[N];
vector<int>G[N];
int n,m,sum,u;
void dfs(int v,int len){
	if(v>n||len>n) return ;
	if(G[v].size()>=m-1&&v!=u) return ;
//	printf("adsafdaa\n");
	for(int i=1;i<=n;i++) if(!vis[i]&&f[i]==len){
		if(v!=u&&G[v].size()>=m-1||u==v&&G[v].size()>=m) continue;
		G[v].push_back(i);
		vis[i]=1;
		sum++;
		dfs(i,len+1);
	}
	return ;
}
void init(){
	for(int i=0;i<N;i++) G[i].clear();
	memset(vis,0,sizeof(vis));
}
int main(){
	int i,j,flag;
	while(scanf("%d%d",&n,&m)!=EOF){
		flag=0;
		sum=0;
		init();
		for(i=1;i<=n;i++){
			scanf("%d",&f[i]);
			if(f[i]==0) u=i;
		}
		vis[u]=1;
		dfs(u,1);
		for(i=1;i<=n;i++) if(!vis[i]){
			flag=1;
			//printf("%d\n",i);
			break;
		}
		if(flag||sum==0) printf("-1\n");
		else {
			printf("%d\n",sum);
			for(i=1;i<=n;i++)
				for(j=0;j<G[i].size();j++) printf("%d %d\n",i,G[i][j]);
		}
	}
}


#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
const int N=200110;
pair<int,int>pa;
vector<int>G[N];
vector<pair<int,int> >ans;
void init(){
    for(int i=0;i<=100110;i++) G[i].clear();
    ans.clear();
}
__int64  min(__int64 a,__int64 b){
    return a<=b?a:b;
}
int main(){
    int n,m,a,i,j,flag;
    while(scanf("%d%d",&n,&m)!=EOF){
        flag=0;
        init();
        for(i=1;i<=n;i++){
            scanf("%d",&a);
             G[a].push_back(i);
        }
        for(i=0;i<=100005;i++){
            if((__int64)G[i].size()*m<(__int64)G[i+1].size()||G[0].size()!=1){
                puts("-1");
                flag=1;
                //printf("%d\n",i);
                break;
            }
            for(j=0;j<G[i].size();j++){
                __int64 len=G[i+1].size();
                for(__int64 k=j*m;k<min(len,(__int64)(j+1)*m);k++){
                    pa.first=G[i][j];
                    pa.second=G[i+1][k];
                    ans.push_back(pa);
                }
            }
            if(i==0) m--;
        }
        if(!flag){
            printf("%I64d\n",(__int64)ans.size());
            for(i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
        }
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
const int N=1000010;
int f[N],vis[N];
vector<int>G[N];
int n,m,flag,sum;
struct node{
	int u;
	int len;
};
queue<node>qu;
void init(){
	while(!qu.empty()) qu.pop();
	for(int i=0;i<N;i++) G[i].clear();
}
void bfs(int u,int len){
	node beg;
	beg.u=u;
	beg.len=len;
	qu.push(beg);
	while(!qu.empty()){
		node en=qu.front();
		node end=en;
		while(en.len<=len&&!qu.empty()){
			qu.pop();
			en=qu.front();
		}
		for(int i=1;i<=n;i++) if(f[i]==len){
			node mid;
			mid.u=i;
			mid.len=len+1;
			qu.push(mid);
			G[end.u].push_back(i);
			sum++;
		}
		if(G[end.u].size()>m){
			flag=1;
			break;
		}
		len++;
	}
}
int main(){
	int u;
	while(scanf("%d%d",&n,&m)!=EOF){
		init();
		for(int i=1;i<=n;i++){
			scanf("%d",&f[i]);
			if(f[i]==0) u=i;
		}
		flag=0;
		sum=0;
		bfs(u,1);

		if(flag||sum==0) printf("-1\n");
		else {
			printf("%d\n",sum);
			for(int i=1;i<=n;i++)
				for(int j=0;j<G[i].size();j++) printf("%d %d\n",i,G[i][j]);
		}
	}

}
/*
7 3
2 2 0 1 3 2 1
6
1 7
2 7
3 4
3 7
4 6
5 6

*/


#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
const int N=100110;
pair<int,int>pa;
vector<int>G[N];
vector<pair<int,int> >ans;
void init(){
    for(int i=0;i<=100110;i++) G[i].clear();
    ans.clear();
}
int main(){
    int n,m,a,i,j,k,flag;
    while(scanf("%d%d",&n,&m)!=EOF){
        flag=0;
        init();
        for(i=1;i<=n;i++){
            scanf("%d",&a);
             G[a].push_back(i);
        }
        for(i=0;i<=100005;i++){
            if(G[i].size()*m<G[i+1].size()||G[0].size()!=1){
                puts("-1");
                flag=1;
                //printf("%d\n",i);
                break;
            }
            for(j=0;j<G[i].size();j++){
                int len=G[i+1].size();
                for(k=j*m;k<min(len,(j+1)*m);k++){
                    pa.first=G[i][j];
                    pa.second=G[i+1][k];
                    ans.push_back(pa);
                }
            }

            if(i==0) m--;
        }
        if(!flag){
            printf("%d\n",ans.size());
            for(i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
        }
    }
}


#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
const int N=200110;
pair<int,int>pa;
vector<int>G[N];
vector<pair<int,int> >ans;
void init(){
    for(int i=0;i<=200110;i++) G[i].clear();
    ans.clear();
}
__int64  min(__int64 a,__int64 b){
    return a<=b?a:b;
}
int main(){
    int n,m,a,i,j,flag;
    while(scanf("%d%d",&n,&m)!=EOF){
        flag=0;
        init();
        for(i=1;i<=n;i++){
            scanf("%d",&a);
             G[a].push_back(i);
        }
        for(i=0;i<=100015;i++){
            if((__int64)G[i].size()*1ll*m<(__int64)G[i+1].size()||G[0].size()!=1){
                puts("-1");
                flag=1;
                //printf("%d\n",i);
                break;
            }
            for(j=0;j<G[i].size();j++){
                __int64 len=G[i+1].size();
                for(__int64 k=j*m*1ll;k<min(len,(__int64)(j+1)*1ll*m);k++){
                    pa.first=G[i][j];
                    pa.second=G[i+1][k];
                    ans.push_back(pa);
                }
            }
            if(i==0) m--;
        }
        if(!flag){
            printf("%I64d\n",(__int64)ans.size());
            for(i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
        }
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int N=100010;
int f[N],vis[N];
vector<int>G[N];
int n,m,sum;
void dfs(int u,int len){
	if(u>n||len>n) return ;
//	printf("adsafdaa\n");
	for(int i=1;i<=n;i++) if(!vis[i]&&f[i]==len&&G[u].size()<m-1){
		G[u].push_back(i);
		vis[i]=1;
		sum++;
		dfs(i,len+1);
	}
	return ;
}
void init(){
	for(int i=0;i<N;i++) G[i].clear();
	memset(vis,0,sizeof(vis));
}
int main(){
	int u,i,j,flag;
	while(scanf("%d%d",&n,&m)!=EOF){
		flag=0;
		sum=0;
		init();
		for(i=1;i<=n;i++){
			scanf("%d",&f[i]);
			if(f[i]==0) u=i;
		}
		vis[u]=1;
		dfs(u,1);
		for(i=1;i<=n;i++) if(!vis[i]){
			flag=1;
			//printf("%d\n",i);
			break;
		}
		if(flag||sum==0) printf("-1\n");
		else {
			printf("%d\n",sum);
			for(i=1;i<=n;i++)
				for(j=0;j<G[i].size();j++) printf("%d %d\n",i,G[i][j]);
		}
	}
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <sstream>
using namespace std;

#define rep(i,a) for(int i=0; i<a;i++)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a; i>=b; i--)
#define mp make_pair
#define ll long long unsigned
#define sz(x) (x).size()
#define pb push_back
#define endl '\n'

template <typename T>
  string NumberToString ( T Number ) {
     ostringstream ss;
     ss << Number;
     return ss.str();
  }

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, current;
	cin >> n >> k;
	vector<vector<int> > set_of_distances;
	set_of_distances.resize(n+1);

	forn(i, 1, n + 1) {
		cin >> current;
		(set_of_distances[current]).pb(i);
	}
	if(sz(set_of_distances[0]) != 1 || sz(set_of_distances[1]) > k) {
		cout << -1 << endl;
		return 0;
	}
	bool fin = false;
	forn(i, 1, n) {
		if (sz(set_of_distances[i]) == 0) {
			fin = true;
		} else if(fin || sz(set_of_distances[i]) * (k - 1) < sz(set_of_distances[i+1])) {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << n - 1 << endl;

	rep(i, n) {
		if(sz(set_of_distances[i]) == 0) {
			break;
		}
		int current_node = 0; // El primer nodo del i-esimo nivel
		int current_next_level_node = 0; // El primer nodo del (i+1)-esimo nivel
		int valencia_current_node = 1; // Valencia del nodo actual del cual armar la arista
		while (current_next_level_node < sz(set_of_distances[i+1])) {
			if ((i != 0 && valencia_current_node == k) || (i == 0 && valencia_current_node == k+1)) {
				// cout << "valencia_current_node = " << valencia_current_node << endl;
				// cout << "i = " << i << endl;
				current_node++;
				valencia_current_node = 1;
			}
			cout << set_of_distances[i][current_node] << " " << set_of_distances[i+1][current_next_level_node] << endl;
			current_next_level_node++;
			valencia_current_node++;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <sstream>
using namespace std;

#define rep(i,a) for(int i=0; i<a;i++)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a; i>=b; i--)
#define mp make_pair
#define ll long long unsigned
#define sz(x) (x).size()
#define pb push_back
#define endl '\n'

template <typename T>
  string NumberToString ( T Number ) {
     ostringstream ss;
     ss << Number;
     return ss.str();
  }

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, current;
	cin >> n >> k;
	vector<vector<int> > set_of_distances;
	set_of_distances.resize(n+1);

	forn(i, 1, n + 1) {
		cin >> current;
		(set_of_distances[current]).pb(i);
	}
	if(sz(set_of_distances[0]) != 1 || sz(set_of_distances[1]) > k) {
		cout << -1 << endl;
		return 0;
	}
	bool fin = false;
	forn(i, 1, n) {
		if (sz(set_of_distances[i]) == 0) {
			fin = true;
		} else if(fin || sz(set_of_distances[i]) * (k - 1) < sz(set_of_distances[i+1]) || false) {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << n - 1 << endl;

	rep(i, n) {
		if(sz(set_of_distances[i]) == 0) {
			break;
		}
		int current_node = 0; // El primer nodo del i-esimo nivel
		int current_next_level_node = 0; // El primer nodo del (i+1)-esimo nivel
		int valencia_current_node = 1; // Valencia del nodo actual del cual armar la arista
		while (current_next_level_node < sz(set_of_distances[i+1])) {
			if ((i != 0 && valencia_current_node == k) || (i == 0 && valencia_current_node == k+1)) {
				// cout << "valencia_current_node = " << valencia_current_node << endl;
				// cout << "i = " << i << endl;
				current_node++;
				valencia_current_node = 1;
			}
			cout << set_of_distances[i][current_node] << " " << set_of_distances[i+1][current_next_level_node] << endl;
			current_next_level_node++;
			valencia_current_node++;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <sstream>
using namespace std;

#define rep(i,a) for(int i=0; i<a;i++)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a; i>=b; i--)
#define mp make_pair
#define ll long long unsigned
#define sz(x) (x).size()
#define pb push_back
#define endl '\n'

template <typename T>
  string NumberToString ( T Number ) {
     ostringstream ss;
     ss << Number;
     return ss.str();
  }

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, current;
	cin >> n >> k;
	vector<vector<int> > set_of_distances;
	set_of_distances.resize(n+1);

	forn(i, 1, n + 1) {
		cin >> current;
		(set_of_distances[current]).pb(i);
	}
	if(sz(set_of_distances[0]) != 1) {
		cout << -1 << endl;
		return 0;
	}
	bool fin = false;
	forn(i, 1, n) {
		if (sz(set_of_distances[i]) == 0) {
			fin = true;
		} else if(fin || sz(set_of_distances[i]) * (k - 1) < sz(set_of_distances[i+1])) {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << n - 1 << endl;

	rep(i, n) {
		if(sz(set_of_distances[i]) == 0) {
			break;
		}
		int current_node = 0; // El primer nodo del i-esimo nivel
		int current_next_level_node = 0; // El primer nodo del (i+1)-esimo nivel
		int valencia_current_node = 1; // Valencia del nodo actual del cual armar la arista
		while (current_next_level_node < sz(set_of_distances[i+1])) {
			if (valencia_current_node == k) {
				current_node++;
				valencia_current_node = 1;
			}
			cout << set_of_distances[i][current_node] << " " << set_of_distances[i+1][current_next_level_node] << endl;
			current_next_level_node++;
			valencia_current_node++;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <sstream>
using namespace std;

#define rep(i,a) for(int i=0; i<a;i++)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a; i>=b; i--)
#define mp make_pair
#define ll long long unsigned
#define sz(x) (x).size()
#define pb push_back
#define endl '\n'

template <typename T>
  string NumberToString ( T Number ) {
     ostringstream ss;
     ss << Number;
     return ss.str();
  }

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, current;
	cin >> n >> k;
	vector<vector<int> > set_of_distances;
	set_of_distances.resize(n+1);

	forn(i, 1, n + 1) {
		cin >> current;
		(set_of_distances[current]).pb(i);
	}
	if(sz(set_of_distances[0]) != 1 || sz(set_of_distances[1]) > k) {
		cout << -1 << endl;
		return 0;
	}
	bool fin = false;
	forn(i, 1, n) {
		if (sz(set_of_distances[i]) == 0) {
			fin = true;
		} else if(fin || (sz(set_of_distances[i]) * (k - 1)) + 1 < sz(set_of_distances[i+1])) {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << n - 1 << endl;

	rep(i, n) {
		if(sz(set_of_distances[i]) == 0) {
			break;
		}
		int current_node = 0; // El primer nodo del i-esimo nivel
		int current_next_level_node = 0; // El primer nodo del (i+1)-esimo nivel
		int valencia_current_node = 1; // Valencia del nodo actual del cual armar la arista
		while (current_next_level_node < sz(set_of_distances[i+1])) {
			if ((i != 0 && valencia_current_node == k) || (i == 0 && valencia_current_node == k+1)) {
				// cout << "valencia_current_node = " << valencia_current_node << endl;
				// cout << "i = " << i << endl;
				current_node++;
				valencia_current_node = 1;
			}
			cout << set_of_distances[i][current_node] << " " << set_of_distances[i+1][current_next_level_node] << endl;
			current_next_level_node++;
			valencia_current_node++;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <sstream>
using namespace std;

#define rep(i,a) for(int i=0; i<a;i++)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a; i>=b; i--)
#define mp make_pair
#define ll long long unsigned
#define sz(x) (x).size()
#define pb push_back
#define endl '\n'

template <typename T>
  string NumberToString ( T Number ) {
     ostringstream ss;
     ss << Number;
     return ss.str();
  }

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, current;
	cin >> n >> k;
	vector<vector<int> > set_of_distances;
	set_of_distances.resize(n+1);

	forn(i, 1, n + 1) {
		cin >> current;
		(set_of_distances[current]).pb(i);
	}
	if(sz(set_of_distances[0]) != 1 || sz(set_of_distances[1]) > k) {
		cout << -1 << endl;
		return 0;
	}
	bool fin = false;
	forn(i, 1, n) {
		if (sz(set_of_distances[i]) == 0) {
			fin = true;
		} else if(fin || sz(set_of_distances[i]) * (k - 1) <= sz(set_of_distances[i+1])) {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << n - 1 << endl;

	rep(i, n) {
		if(sz(set_of_distances[i]) == 0) {
			break;
		}
		int current_node = 0; // El primer nodo del i-esimo nivel
		int current_next_level_node = 0; // El primer nodo del (i+1)-esimo nivel
		int valencia_current_node = 1; // Valencia del nodo actual del cual armar la arista
		while (current_next_level_node < sz(set_of_distances[i+1])) {
			if ((i != 0 && valencia_current_node == k) || (i == 0 && valencia_current_node == k+1)) {
				// cout << "valencia_current_node = " << valencia_current_node << endl;
				// cout << "i = " << i << endl;
				current_node++;
				valencia_current_node = 1;
			}
			cout << set_of_distances[i][current_node] << " " << set_of_distances[i+1][current_next_level_node] << endl;
			current_next_level_node++;
			valencia_current_node++;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <sstream>
using namespace std;

#define rep(i,a) for(int i=0; i<a;i++)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a; i>=b; i--)
#define mp make_pair
#define ll long long unsigned
#define sz(x) (x).size()
#define pb push_back
#define endl '\n'

template <typename T>
  string NumberToString ( T Number ) {
     ostringstream ss;
     ss << Number;
     return ss.str();
  }

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, current;
	cin >> n >> k;
	vector<vector<int> > set_of_distances;
	set_of_distances.resize(n+1);

	forn(i, 1, n + 1) {
		cin >> current;
		(set_of_distances[current]).pb(i);
	}
	if(sz(set_of_distances[0]) != 1 || sz(set_of_distances[1]) > k) {
		cout << -1 << endl;
		return 0;
	}
	bool fin = false;
	forn(i, 1, n) {
		if (sz(set_of_distances[i]) == 0) {
			fin = true;
		} else if(fin) {
			cout << -1 << endl;
			return 0;
		} else if(sz(set_of_distances[i]) * (k - 1) < sz(set_of_distances[i+1]) || false) {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << n - 1 << endl;

	rep(i, n) {
		if(sz(set_of_distances[i]) == 0) {
			break;
		}
		int current_node = 0; // El primer nodo del i-esimo nivel
		int current_next_level_node = 0; // El primer nodo del (i+1)-esimo nivel
		int valencia_current_node = 1; // Valencia del nodo actual del cual armar la arista
		while (current_next_level_node < sz(set_of_distances[i+1])) {
			if ((i != 0 && valencia_current_node == k) || (i == 0 && valencia_current_node == k+1)) {
				// cout << "valencia_current_node = " << valencia_current_node << endl;
				// cout << "i = " << i << endl;
				current_node++;
				valencia_current_node = 1;
			}
			cout << set_of_distances[i][current_node] << " " << set_of_distances[i+1][current_next_level_node] << endl;
			current_next_level_node++;
			valencia_current_node++;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <sstream>
using namespace std;

#define rep(i,a) for(int i=0; i<a;i++)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a; i>=b; i--)
#define mp make_pair
#define ll long long unsigned
#define sz(x) (x).size()
#define pb push_back
#define endl '\n'

template <typename T>
  string NumberToString ( T Number ) {
     ostringstream ss;
     ss << Number;
     return ss.str();
  }

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, current;
	cin >> n >> k;
	vector<vector<int> > set_of_distances;
	set_of_distances.resize(n+1);

	forn(i, 1, n + 1) {
		cin >> current;
		(set_of_distances[current]).pb(i);
	}
	if(sz(set_of_distances[0]) != 1) {
		cout << -1 << endl;
		return 0;
	}
	bool fin = false;
	forn(i, 1, n) {
		if (sz(set_of_distances[i]) == 0) {
			fin = true;
		} else if(fin || sz(set_of_distances[i]) * (k - 1) < sz(set_of_distances[i+1])) {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << n - 1 << endl;

	rep(i, n) {
		if(sz(set_of_distances[i]) == 0) {
			break;
		}
		int current_node = 0; // El primer nodo del i-esimo nivel
		int current_next_level_node = 0; // El primer nodo del (i+1)-esimo nivel
		int valencia_current_node = 1; // Valencia del nodo actual del cual armar la arista
		while (current_next_level_node < sz(set_of_distances[i+1])) {
			if (valencia_current_node == k) {
				current_node++;
				valencia_current_node = 1;
			}
			cout << set_of_distances[i][current_node] << " " << set_of_distances[i+1][current_next_level_node] << endl;
			current_next_level_node++;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <sstream>
using namespace std;

#define rep(i,a) for(int i=0; i<a;i++)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a; i>=b; i--)
#define mp make_pair
#define ll long long unsigned
#define sz(x) (x).size()
#define pb push_back
#define endl '\n'

template <typename T>
  string NumberToString ( T Number ) {
     ostringstream ss;
     ss << Number;
     return ss.str();
  }

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, current;
	cin >> n >> k;
	vector<vector<int> > set_of_distances;
	set_of_distances.resize(n+1);

	forn(i, 1, n + 1) {
		cin >> current;
		(set_of_distances[current]).pb(i);
	}
	if(sz(set_of_distances[0]) != 1 || sz(set_of_distances[1]) > k) {
		cout << -1 << endl;
		return 0;
	}
	bool fin = false;
	forn(i, 1, n) {
		if (sz(set_of_distances[i]) == 0) {
			fin = true;
		} else if(fin) {
			cout << -1 << endl;
			return 0;
		} else if((sz(set_of_distances[i]) * k) - 1 < sz(set_of_distances[i+1])) {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << n - 1 << endl;

	rep(i, n) {
		if(sz(set_of_distances[i]) == 0) {
			break;
		}
		int current_node = 0; // El primer nodo del i-esimo nivel
		int current_next_level_node = 0; // El primer nodo del (i+1)-esimo nivel
		int valencia_current_node = 1; // Valencia del nodo actual del cual armar la arista
		while (current_next_level_node < sz(set_of_distances[i+1])) {
			if ((i != 0 && valencia_current_node == k) || (i == 0 && valencia_current_node == k+1)) {
				// cout << "valencia_current_node = " << valencia_current_node << endl;
				// cout << "i = " << i << endl;
				current_node++;
				valencia_current_node = 1;
			}
			cout << set_of_distances[i][current_node] << " " << set_of_distances[i+1][current_next_level_node] << endl;
			current_next_level_node++;
			valencia_current_node++;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <sstream>
using namespace std;

#define rep(i,a) for(int i=0; i<a;i++)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a; i>=b; i--)
#define mp make_pair
#define ll long long unsigned
#define sz(x) (x).size()
#define pb push_back
#define endl '\n'

template <typename T>
  string NumberToString ( T Number ) {
     ostringstream ss;
     ss << Number;
     return ss.str();
  }

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, current;
	cin >> n >> k;
	vector<vector<int> > set_of_distances;
	set_of_distances.resize(n+1);

	forn(i, 1, n + 1) {
		cin >> current;
		(set_of_distances[current]).pb(i);
	}
	if(sz(set_of_distances[0]) != 1) {
		cout << -1 << endl;
		return 0;
	}
	bool fin = false;
	forn(i, 1, n) {
		if (sz(set_of_distances[i]) == 0) {
			fin = true;
		} else if(fin || sz(set_of_distances[i]) * (k - 1) < sz(set_of_distances[i+1])) {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << n - 1 << endl;

	rep(i, n) {
		if(sz(set_of_distances[i]) == 0) {
			break;
		}
		int current_node = 0; // El primer nodo del i-esimo nivel
		int current_next_level_node = 0; // El primer nodo del (i+1)-esimo nivel
		int valencia_current_node = 1; // Valencia del nodo actual del cual armar la arista
		while (current_next_level_node < sz(set_of_distances[i+1])) {
			if ((i != 0 && valencia_current_node == k) || (i == 0 && valencia_current_node == k+1)) {
				// cout << "valencia_current_node = " << valencia_current_node << endl;
				// cout << "i = " << i << endl;
				current_node++;
				valencia_current_node = 1;
			}
			cout << set_of_distances[i][current_node] << " " << set_of_distances[i+1][current_next_level_node] << endl;
			current_next_level_node++;
			valencia_current_node++;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <sstream>
using namespace std;

#define rep(i,a) for(int i=0; i<a;i++)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a; i>=b; i--)
#define mp make_pair
#define ll long long unsigned
#define sz(x) (x).size()
#define pb push_back
#define endl '\n'

template <typename T>
  string NumberToString ( T Number ) {
     ostringstream ss;
     ss << Number;
     return ss.str();
  }

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, current;
	cin >> n >> k;
	vector<vector<int> > set_of_distances;
	set_of_distances.resize(n+1);

	forn(i, 1, n + 1) {
		cin >> current;
		(set_of_distances[current]).pb(i);
	}
	if(sz(set_of_distances[0]) != 1) {
		cout << -1 << endl;
		return 0;
	}
	bool fin = false;
	forn(i, 1, n) {
		if (sz(set_of_distances[i]) == 0) {
			if(fin) {
				cout << -1 << endl;
				return 0;
			} else {
				fin = true;
			}
		} else if(sz(set_of_distances[i]) * (k - 1) < sz(set_of_distances[i+1])) {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << n - 1 << endl;

	rep(i, n) {
		if(sz(set_of_distances[i]) == 0) {
			break;
		}
		int current_node = 0; // El primer nodo del i-esimo nivel
		int current_next_level_node = 0; // El primer nodo del (i+1)-esimo nivel
		int valencia_current_node = 1; // Valencia del nodo actual del cual armar la arista
		while (current_next_level_node < sz(set_of_distances[i+1])) {
			if (valencia_current_node == k) {
				current_node++;
				valencia_current_node = 1;
			}
			cout << set_of_distances[i][current_node] << " " << set_of_distances[i+1][current_next_level_node] << endl;
			current_next_level_node++;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <sstream>
using namespace std;

#define rep(i,a) for(int i=0; i<a;i++)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a; i>=b; i--)
#define mp make_pair
#define ll long long unsigned
#define sz(x) (x).size()
#define pb push_back
#define endl '\n'

template <typename T>
  string NumberToString ( T Number ) {
     ostringstream ss;
     ss << Number;
     return ss.str();
  }

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, current;
	cin >> n >> k;
	vector<vector<int> > set_of_distances;
	set_of_distances.resize(n+1);

	forn(i, 1, n + 1) {
		cin >> current;
		(set_of_distances[current]).pb(i);
	}
	if(sz(set_of_distances[0]) != 1) {
		cout << -1 << endl;
		return 0;
	}
	bool fin = false;
	forn(i, 1, n) {
		if (sz(set_of_distances[i]) == 0) {
			if(fin) {
				cout << -1 << endl;
				return 0;
			} else {
				fin = true;
			}
		} else if(sz(set_of_distances[i]) * (k - 1) < sz(set_of_distances[i+1])) {
			cout << -1 << endl;
			return 0;
		}
	}

	rep(i, n) {
		if(sz(set_of_distances[i]) == 0) {
			break;
		}
		int current_node = 0; // El primer nodo del i-esimo nivel
		int current_next_level_node = 0; // El primer nodo del (i+1)-esimo nivel
		int valencia_current_node = 1; // Valencia del nodo actual del cual armar la arista
		while (current_next_level_node < sz(set_of_distances[i+1])) {
			if (valencia_current_node == k) {
				current_node++;
				valencia_current_node = 1;
			}
			cout << set_of_distances[i][current_node] << " " << set_of_distances[i+1][current_next_level_node] << endl;
			current_next_level_node++;
		}
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int SIZE=100005;
vector<int> G[SIZE];
int ID,from[SIZE],to[SIZE];
int main()
{
    int i,j,l;
    int n,k;
    int now;
    while(scanf("%d%d",&n,&k)!=EOF){
        for(i=0;i<n;i++) G[i].clear();
        int flag=1;
        int num,d;
        for(i=1;i<=n;i++){
            scanf("%d",&d);
            G[d].push_back(i);
        }
        ID=0;
        if(G[0].size()!=1){printf("-1\n");continue;}
        for(i=1;i<=n;i++){
            now=0;j=0;
            if(G[i-1].size()*k<G[i].size()){
                flag=0;
                break;
            }
            while(j<G[i].size()){
                from[ID]=G[i-1][now];
                to[ID]=G[i][j];
                now=(now+1)%G[i-1].size();
                j++;ID++;
            }
        }
        if(flag==0){
            printf("-1\n");
            continue;
        }
        printf("%d\n",ID);
        for(i=0;i<ID;i++)
            printf("%d %d\n",from[i],to[i]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int SIZE=100005;
const int SIZE2=1000005;
vector<int> G[SIZE];
int ID,from[SIZE2],to[SIZE2];
int main()
{
    int i,j,l;
    int n,k;
    int now,top;
    while(scanf("%d%d",&n,&k)!=EOF){
        top=-1;
        for(i=0;i<n;i++) G[i].clear();
        int flag=1,num,d;
        for(i=1;i<=n;i++){
            scanf("%d",&d);
            G[d].push_back(i);
            top=max(top,d);
        }
        ID=0;
        if(G[0].size()!=1){printf("-1\n");continue;}
        for(i=1;i<=top;i++){
            now=j=0;
            if(G[i-1].size()*k<G[i].size()){
                flag=0;
                break;
            }
            while(j<G[i].size()){
                from[ID]=G[i-1][now];
                to[ID]=G[i][j];
                now=(now+1)%G[i-1].size();
                j++;ID++;
            }
        }
        if(flag==0){
            printf("-1\n");
            continue;
        }
        printf("%d\n",ID);
        for(i=0;i<ID;i++)
            printf("%d %d\n",from[i],to[i]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int SIZE=100005;
const int SIZE2=1000005;
vector<int> G[SIZE];
int ID,from[SIZE2],to[SIZE2];
int main()
{
    int i,j,l;
    int n,k;
    int now,top;
    while(scanf("%d%d",&n,&k)!=EOF){
        top=0;
        for(i=0;i<SIZE;i++) G[i].clear();
        int flag=1,d;
        for(i=1;i<=n;i++){
            scanf("%d",&d);
            G[d].push_back(i);
            top=max(top,d);
        }
        ID=0;
        //if(G[0].size()!=1){printf("-1\n");continue;}
        for(i=1;i<=top;i++){
            now=j=0;
            if(G[i-1].size()*k<G[i].size()){
                flag=0;
                break;
            }
            while(j<G[i].size()){
                from[ID]=G[i-1][now++];
                to[ID]=G[i][j];
                now%=G[i-1].size();
                j++;ID++;
            }
        }
        if(!flag){
            printf("-1\n");
            continue;
        }
        printf("%d\n",ID);
        for(i=0;i<ID;i++)
            printf("%d %d\n",from[i],to[i]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int SIZE=100005;
const int SIZE2=1000005;
vector<int> G[SIZE];
int ID,from[SIZE2],to[SIZE2];
int main()
{
    int i,j,l;
    int n,k;
    int now,top;
    while(scanf("%d%d",&n,&k)!=EOF){
        top=0;
        for(i=0;i<SIZE;i++) G[i].clear();
        int flag=1,d;
        for(i=1;i<=n;i++){
            scanf("%d",&d);
            G[d].push_back(i);
            top=max(top,d);
        }
        ID=0;
        if(G[0].size()!=1){printf("-1\n");continue;}
        for(i=1;i<=top;i++){
            now=j=0;
            if(G[i-1].size()*k<G[i].size()&&G[i-1].size()!=0){
                flag=0;
                break;
            }
            while(j<G[i].size()){
                from[ID]=G[i-1][now++];
                to[ID]=G[i][j];
                now%=G[i-1].size();
                j++;ID++;
            }
        }
        if(!flag){
            printf("-1\n");
            continue;
        }
        printf("%d\n",ID);
        for(i=0;i<ID;i++)
            printf("%d %d\n",from[i],to[i]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int SIZE=100005;
const int SIZE2=1000005;
vector<int> G[SIZE];
int ID,from[SIZE2],to[SIZE2];
int main()
{
    int i,j,l;
    int n,k;
    int now,top;
    while(scanf("%d%d",&n,&k)!=EOF){
        top=0;
        for(i=0;i<SIZE;i++) G[i].clear();
        int flag=1,d;
        for(i=1;i<=n;i++){
            scanf("%d",&d);
            G[d].push_back(i);
            top=max(top,d);
        }
        ID=0;
        if(G[0].size()!=1){printf("-1\n");continue;}
        for(i=1;i<=top;i++){
            now=j=0;
            if(G[i-1].size()*k<G[i].size()){
                flag=0;
                break;
            }
            while(j<G[i].size()){
                from[ID]=G[i-1][now++];
                to[ID]=G[i][j];
                now%=G[i-1].size();
                j++;ID++;
            }
            if(i==1) k--;
        }
        if(!flag){
            printf("-1\n");
            continue;
        }
        printf("%d\n",ID);
        for(i=0;i<ID;i++)
            printf("%d %d\n",from[i],to[i]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int SIZE=100005;
const int SIZE2=1000005;
vector<int> G[SIZE];
int ID,from[SIZE2],to[SIZE2];
int main()
{
    int i,j,l;
    int n,k;
    int now,top;
    while(scanf("%d%d",&n,&k)!=EOF){
        top=0;
        for(i=0;i<SIZE;i++) G[i].clear();
        int flag=1,d;
        for(i=1;i<=n;i++){
            scanf("%d",&d);
            G[d].push_back(i);
            top=max(top,d);
        }
        ID=0;
        if(G[0].size()!=1){printf("-1\n");continue;}
        for(i=1;i<=top;i++){
            now=j=0;
            if((G[i-1].size()*k)<G[i].size()){
                flag=0;
                break;
            }
            while(j<G[i].size()){
                from[ID]=G[i-1][now++];
                to[ID]=G[i][j];
                now%=G[i-1].size();
                j++;ID++;
            }
        }
        if(!flag){
            printf("-1\n");
            continue;
        }
        printf("%d\n",ID);
        for(i=0;i<ID;i++)
            printf("%d %d\n",from[i],to[i]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int SIZE=100005;
const int SIZE2=1000005;
vector<int> G[SIZE];
int ID,from[SIZE2],to[SIZE2];
int main()
{
    int i,j,l;
    int n,k;
    int now;
    while(scanf("%d%d",&n,&k)!=EOF){
        for(i=0;i<n;i++) G[i].clear();
        int flag=1;
        int num,d;
        for(i=1;i<=n;i++){
            scanf("%d",&d);
            G[d].push_back(i);
        }
        ID=0;
        if(G[0].size()!=1){printf("-1\n");continue;}
        for(i=1;i<=n;i++){
            now=0;j=0;
            if(G[i-1].size()*k<G[i].size()){
                flag=0;
                break;
            }
            while(j<G[i].size()){
                from[ID]=G[i-1][now];
                to[ID]=G[i][j];
                now=(now+1)%G[i-1].size();
                j++;ID++;
            }
        }
        if(flag==0){
            printf("-1\n");
            continue;
        }
        printf("%d\n",ID);
        for(i=0;i<ID;i++)
            printf("%d %d\n",from[i],to[i]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int SIZE=100005;
vector<int> G[SIZE];
int ID,from[SIZE],to[SIZE];
int vis[SIZE];
int main()
{
    int i,j,l;
    int n,k;
    int now;
    while(scanf("%d%d",&n,&k)!=EOF){
        for(i=0;i<n;i++) G[i].clear();
        int flag=1;
        int num,d;
        for(i=1;i<=n;i++){
            scanf("%d",&d);
            G[d].push_back(i);
        }
        ID=0;
        if(G[0].size()!=1){printf("-1\n");continue;}
        for(i=1;i<=n;i++){
            now=0;j=0;
            if(G[i-1].size()*k<G[i-1].size()){
                flag=0;
                break;
            }
            while(j<G[i].size()){
                from[ID]=G[i-1][now];
                to[ID]=G[i][j];
                now=(now+1)%G[i-1].size();
                j++;ID++;
            }
        }
        printf("%d\n",ID);
        for(i=0;i<ID;i++)
            printf("%d %d\n",from[i],to[i]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int SIZE=100005;
const int SIZE2=1000005;
vector<int> G[SIZE];
int ID,from[SIZE2],to[SIZE2];
int main()
{
    int i,j,l;
    int n,k;
    int now,top;
    while(scanf("%d%d",&n,&k)!=EOF){
        top=0;
        for(i=0;i<SIZE;i++) G[i].clear();
        int flag=1,d;
        for(i=1;i<=n;i++){
            scanf("%d",&d);
            G[d].push_back(i);
            top=max(top,d);
        }
        ID=0;
        if(G[0].size()!=1){printf("-1\n");continue;}
        for(i=1;i<=top;i++){
            now=j=0;
            if((G[i-1].size()*(k-1))<G[i].size()){
                flag=0;
                break;
            }
            while(j<G[i].size()){
                from[ID]=G[i-1][now++];
                to[ID]=G[i][j];
                now%=G[i-1].size();
                j++;ID++;
            }
        }
        if(!flag){
            printf("-1\n");
            continue;
        }
        printf("%d\n",ID);
        for(i=0;i<ID;i++)
            printf("%d %d\n",from[i],to[i]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int SIZE=100005;
const int SIZE2=1000005;
vector<int> G[SIZE];
int ID,from[SIZE2],to[SIZE2];
int main()
{
    int i,j,l;
    int n,k;
    int now,top;
    while(scanf("%d%d",&n,&k)!=EOF){
        top=0;
        for(i=0;i<SIZE;i++) G[i].clear();
        int flag=1,d;
        for(i=1;i<=n;i++){
            scanf("%d",&d);
            G[d].push_back(i);
            top=max(top,d);
        }
        ID=0;
        if(G[0].size()!=1){printf("-1\n");continue;}
        for(i=1;i<=top;i++){
            now=j=0;
            if((long long)G[i-1].size()*k<(long long)G[i].size()){
                flag=0;
                break;
            }
            while(j<G[i].size()){
                from[ID]=G[i-1][now++];
                to[ID]=G[i][j];
                now%=G[i-1].size();
                j++;ID++;
            }
            if(i==1) k--;
        }
        if(!flag){
            printf("-1\n");
            continue;
        }
        printf("%d\n",ID);
        for(i=0;i<ID;i++)
            printf("%d %d\n",from[i],to[i]);
    }
    return 0;
}


 #include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll,int> pli;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <string> vs;

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPD(i, n) for (int i = n; i > 0; i--)
#define memset(a,b) memset(a, b, sizeof(a))
#define ll long long

const
   char  in[] = "data.inp";
   char  out[]  = "data.out";

struct  pt {
	long x, y;
};

long  n, next[100100], k, b[1000100], c[1000100], m;
pt a[100100];

void  openfile()
{
	freopen(in, "r", stdin);
	freopen(out, "w", stdout);
}

void  readfile()
{
	cin >> n >> k;
	FOR (i, 1, n)
	{
		cin >> a[i].x;
		a[i].y = i;
	}

}

bool  cmp(pt a, pt b)
{
	return(a.x < b.x);
}

void  process()
{
	sort(a + 1, a + n + 1, cmp);
	FOR (i, 2, n)
	  if (a[i].x != a[i - 1].x)
	    next[i - 1] = i;

	FORD (i, n - 1, 1)
	  if (a[i].x == a[i + 1].x)
	    next[i] = next[i + 1];

	long t = 1;
	int i = 2;
	while (i <= n)
	{
		//cout << a[t].y << " " << a[i].y << endl;

		if (a[t].x == a[i].x)
		  break;
		  m++;
		b[m] = a[t].y;  c[m] = a[i].y;
		long j = i + 1;
		int sl = 1;
		while (a[j].x == a[i].x)
		{
			if (sl == k)
			{
				t++;
				sl = 0;
			}

			sl++;
			//cout << a[t].y << " " << a[j].y << endl;
			m++;
			b[m] = a[t].y;   c[m]= a[j].y;
			j++;
		}
		i = j;
		t = next[t];
	}
	if (m == 0)
	  cout << -1;
	else
	{
		cout << m << endl;
		FOR (i, 1, m)
		  cout << b[i] << " " <<c[i] << endl;
	}
}

int main()
{
	//openfile();
	readfile();
	process();
}


 #include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll,int> pli;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <string> vs;

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPD(i, n) for (int i = n; i > 0; i--)
#define memset(a,b) memset(a, b, sizeof(a))
#define ll long long

const
   char  in[] = "data.inp";
   char  out[]  = "data.out";

struct  pt {
    long x, y;
};

long  n, next[100100], k, b[1000100], c[1000100], m;
pt a[100100];

void  openfile()
{
    freopen(in, "r", stdin);
    freopen(out, "w", stdout);
}

void  readfile()
{
    cin >> n >> k;
    FOR (i, 1, n)
    {
        cin >> a[i].x;
        a[i].y = i;
    }

}

bool  cmp(pt a, pt b)
{
    return(a.x < b.x);
}

void  process()
{
    sort(a + 1, a + n + 1, cmp);
    FOR (i, 2, n)
      if (a[i].x != a[i - 1].x)
        next[i - 1] = i;

    FORD (i, n - 1, 1)
      if (a[i].x == a[i + 1].x)
        next[i] = next[i + 1];

    long t = 1;
    int i = 2;
    while (i <= n)
    {
        //cout << a[t].y << " " << a[i].y << endl;

        if (a[t].x != a[i].x - 1)
          break;
          m++;
        b[m] = a[t].y;  c[m] = a[i].y;
        long j = i + 1;
        int sl = 1;
        while (a[j].x == a[i].x)
        {
            if (sl == k)
            {
                t++;
                sl = 0;
            }

            sl++;
            //cout << a[t].y << " " << a[j].y << endl;
            m++;
            b[m] = a[t].y;   c[m]= a[j].y;
            j++;
        }
        i = j;
        t = next[t];
    }
    if (m == 0)
      cout << -1;
    else
    {
        cout << m << endl;
        FOR (i, 1, m)
          cout << b[i] << " " <<c[i] << endl;
    }
}

int main()
{
  //  openfile();
    readfile();
    process();
}


 #include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll,int> pli;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <string> vs;

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPD(i, n) for (int i = n; i > 0; i--)
#define memset(a,b) memset(a, b, sizeof(a))
#define ll long long

const
   char  in[] = "data.inp";
   char  out[]  = "data.out";

struct  pt {
	long x, y;
};

long  n, next[100100], k, b[1000100], c[1000100], m;
pt a[100100];

void  openfile()
{
	freopen(in, "r", stdin);
	freopen(out, "w", stdout);
}

void  readfile()
{
	cin >> n >> k;
	FOR (i, 1, n)
	{
		cin >> a[i].x;
		a[i].y = i;
	}

}

bool  cmp(pt a, pt b)
{
	return(a.x < b.x);
}

void  process()
{
	//k--;
	sort(a + 1, a + n + 1, cmp);

	FOR (i, 2, n)
	  if (a[i].x != a[i - 1].x)
	    next[i - 1] = i;

	FORD (i, n - 1, 1)
	  if (a[i].x == a[i + 1].x)
	    next[i] = next[i + 1];

	long t = 1;
	int i = 2;
	if (a[1].x == 0)
	while (i <= n)
	{
		//cout << a[t].y << " " << a[i].y << endl;

		m++;
		b[m] = a[t].y;  c[m] = a[i].y;

		long j = i + 1;
		int sl = 2;
		if (a[t].x == 0)
		  sl = 1;
		if (sl == k + 1)
			t++;
		if (a[t].x != a[i].x - 1)
		{
		  m = 0;
		  break;
		}
		while (a[j].x == a[i].x)
		{
			if (sl == k)
			{
				t++;
				sl = 1;
			}
			sl++;

			//cout << a[t].y << " " << a[j].y << endl;
			m++;
			b[m] = a[t].y;   c[m]= a[j].y;
			j++;
		}
		i = j;
		t = next[t];
	}
	if (m == 0)
	  cout << -1;
	else
	{
		cout << m << endl;
		FOR (i, 1, m)
		  cout << b[i] << " " <<c[i] << endl;
	}
}

int main()
{
	//openfile();
	readfile();
	process();
}


 #include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll,int> pli;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <string> vs;

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPD(i, n) for (int i = n; i > 0; i--)
#define memset(a,b) memset(a, b, sizeof(a))
#define ll long long

const
   char  in[] = "data.inp";
   char  out[]  = "data.out";

struct  pt {
	long x, y;
};

long  n, next[100100], k, b[1000100], c[1000100], m;
pt a[100100];

void  openfile()
{
	freopen(in, "r", stdin);
	freopen(out, "w", stdout);
}

void  readfile()
{
	cin >> n >> k;
	FOR (i, 1, n)
	{
		cin >> a[i].x;
		a[i].y = i;
	}

}

bool  cmp(pt a, pt b)
{
	return(a.x < b.x);
}

void  process()
{
	//k--;
	sort(a + 1, a + n + 1, cmp);

	FOR (i, 2, n)
	  if (a[i].x != a[i - 1].x)
	    next[i - 1] = i;

	FORD (i, n - 1, 1)
	  if (a[i].x == a[i + 1].x)
	    next[i] = next[i + 1];

	long t = 1;
	int i = 2;
	while (i <= n)
	{
		//cout << a[t].y << " " << a[i].y << endl;

		m++;
		b[m] = a[t].y;  c[m] = a[i].y;

		long j = i + 1;
		int sl = 2;
		if (a[t].x == 0)
		  sl = 1;
		if (sl == k + 1)
			t++;
		if (a[t].x != a[i].x - 1)
		{
		  m = 0;
		  break;
		}
		while (a[j].x == a[i].x)
		{
			if (sl == k)
			{
				t++;
				sl = 0;
			}
			sl++;

			//cout << a[t].y << " " << a[j].y << endl;
			m++;
			b[m] = a[t].y;   c[m]= a[j].y;
			j++;
		}
		i = j;
		t = next[t];
	}
	if (m == 0)
	  cout << -1;
	else
	{
		cout << m << endl;
		FOR (i, 1, m)
		  cout << b[i] << " " <<c[i] << endl;
	}
}

int main()
{
	//openfile();
	readfile();
	process();
}


 #include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll,int> pli;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <string> vs;

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPD(i, n) for (int i = n; i > 0; i--)
#define memset(a,b) memset(a, b, sizeof(a))
#define ll long long

const
   char  in[] = "data.inp";
   char  out[]  = "data.out";

struct  pt {
	long x, y;
};

long  n, next[100100], k, b[1000100], c[1000100], m;
pt a[100100];

void  openfile()
{
	freopen(in, "r", stdin);
	freopen(out, "w", stdout);
}

void  readfile()
{
	cin >> n >> k;
	FOR (i, 1, n)
	{
		cin >> a[i].x;
		a[i].y = i;
	}

}

bool  cmp(pt a, pt b)
{
	return(a.x < b.x);
}

void  process()
{
	//k--;
	sort(a + 1, a + n + 1, cmp);

	FOR (i, 2, n)
	  if (a[i].x != a[i - 1].x)
	    next[i - 1] = i;

	FORD (i, n - 1, 1)
	  if (a[i].x == a[i + 1].x)
	    next[i] = next[i + 1];

	long t = 1;
	int i = 2;
	while (i <= n)
	{
		//cout << a[t].y << " " << a[i].y << endl;

		m++;
		b[m] = a[t].y;  c[m] = a[i].y;

		long j = i + 1;
		int sl = 2;
		if (a[t].x == 0)
		  sl = 1;
		if (sl == k + 1)
			t++;
		if (a[t].x != a[i].x - 1)
		{
		  m = 0;
		  break;
		}
		while (a[j].x == a[i].x)
		{
			if (sl == k)
			{
				t++;
				sl = 1;
			}
			sl++;

			//cout << a[t].y << " " << a[j].y << endl;
			m++;
			b[m] = a[t].y;   c[m]= a[j].y;
			j++;
		}
		i = j;
		t = next[t];
	}
	if (m == 0)
	  cout << -1;
	else
	{
		cout << m << endl;
		FOR (i, 1, m)
		  cout << b[i] << " " <<c[i] << endl;
	}
}

int main()
{
	//openfile();
	readfile();
	process();
}


 #include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll,int> pli;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <string> vs;

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPD(i, n) for (int i = n; i > 0; i--)
#define memset(a,b) memset(a, b, sizeof(a))
#define ll long long

const
   char  in[] = "data.inp";
   char  out[]  = "data.out";

struct  pt {
	long x, y;
};

long  n, next[100100], k, b[1000100], c[1000100], m;
pt a[100100];

void  openfile()
{
	freopen(in, "r", stdin);
	freopen(out, "w", stdout);
}

void  readfile()
{
	cin >> n >> k;
	FOR (i, 1, n)
	{
		cin >> a[i].x;
		a[i].y = i;
	}

}

bool  cmp(pt a, pt b)
{
	return(a.x < b.x);
}

void  process()
{
	k--;
	sort(a + 1, a + n + 1, cmp);
	FOR (i, 2, n)
	  if (a[i].x != a[i - 1].x)
	    next[i - 1] = i;

	FORD (i, n - 1, 1)
	  if (a[i].x == a[i + 1].x)
	    next[i] = next[i + 1];

	long t = 1;
	int i = 2;
	while (i <= n)
	{
		//cout << a[t].y << " " << a[i].y << endl;

		if (a[t].x != a[i].x - 1)
		  break;
		  m++;
		b[m] = a[t].y;  c[m] = a[i].y;

		long j = i + 1;
		int sl = 1;
		if (a[t].x == 0)
		  sl = 0;
		while (a[j].x == a[i].x)
		{
			if (sl == k)
			{
				t++;
				sl = 0;
			}

			sl++;
			//cout << a[t].y << " " << a[j].y << endl;
			m++;
			b[m] = a[t].y;   c[m]= a[j].y;
			j++;
		}
		i = j;
		t = next[t];
	}
	if (m == 0)
	  cout << -1;
	else
	{
		cout << m << endl;
		FOR (i, 1, m)
		  cout << b[i] << " " <<c[i] << endl;
	}
}

int main()
{
	//openfile();
	readfile();
	process();
}


 #include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll,int> pli;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <string> vs;

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPD(i, n) for (int i = n; i > 0; i--)
#define memset(a,b) memset(a, b, sizeof(a))
#define ll long long

const
   char  in[] = "data.inp";
   char  out[]  = "data.out";

struct  pt {
    long x, y;
};

long  n, next[100100], k, b[1000100], c[1000100], m;
pt a[100100];

void  openfile()
{
    freopen(in, "r", stdin);
    freopen(out, "w", stdout);
}

void  readfile()
{
    cin >> n >> k;
    FOR (i, 1, n)
    {
        cin >> a[i].x;
        a[i].y = i;
    }

}

bool  cmp(pt a, pt b)
{
    return(a.x < b.x);
}

void  process()
{
    sort(a + 1, a + n + 1, cmp);
    FOR (i, 2, n)
      if (a[i].x != a[i - 1].x)
        next[i - 1] = i;

    FORD (i, n - 1, 1)
      if (a[i].x == a[i + 1].x)
        next[i] = next[i + 1];

    long t = 1;
    int i = 2;
    while (i <= n)
    {
        //cout << a[t].y << " " << a[i].y << endl;

        if (a[t].x != a[i].x - 1)
          break;
          m++;
        b[m] = a[t].y;  c[m] = a[i].y;
        long j = i + 1;
        int sl = 1;
        while (a[j].x == a[i].x)
        {
            if (sl == k)
            {
                t++;
                sl = 0;
            }

            sl++;
            //cout << a[t].y << " " << a[j].y << endl;
            m++;
            b[m] = a[t].y;   c[m]= a[j].y;
            j++;
        }
        i = j;
        t = next[t];
    }
    if (m == 0)
      cout << -1;
    else
    {
        cout << m << endl;
        FOR (i, 1, m)
          cout << b[i] << " " <<c[i] << endl;
    }
}

int main()
{
    openfile();
    readfile();
    process();
}


 #include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll,int> pli;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <string> vs;

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPD(i, n) for (int i = n; i > 0; i--)
#define memset(a,b) memset(a, b, sizeof(a))
#define ll long long

const
   char  in[] = "data.inp";
   char  out[]  = "data.out";

struct  pt {
    long x, y;
};

long  n, next[100100], k, b[1000100], c[1000100], m;
pt a[100100];

void  openfile()
{
    freopen(in, "r", stdin);
    freopen(out, "w", stdout);
}

void  readfile()
{
    cin >> n >> k;
    FOR (i, 1, n)
    {
        cin >> a[i].x;
        a[i].y = i;
    }

}

bool  cmp(pt a, pt b)
{
    return(a.x < b.x);
}

void  process()
{
    k--;
    sort(a + 1, a + n + 1, cmp);
    FOR (i, 2, n)
      if (a[i].x != a[i - 1].x)
        next[i - 1] = i;

    FORD (i, n - 1, 1)
      if (a[i].x != a[i + 1].x - 1)
        next[i] = next[i + 1];

    long t = 1;
    int i = 2;
    while (i <= n)
    {
        //cout << a[t].y << " " << a[i].y << endl;

        if (a[t].x != a[i].x - 1)
          break;
          m++;
        b[m] = a[t].y;  c[m] = a[i].y;
        long j = i + 1;
        int sl = 1;
        while (a[j].x == a[i].x)
        {
            if (sl == k)
            {
                t++;
                sl = 0;
            }

            sl++;
            //cout << a[t].y << " " << a[j].y << endl;
            m++;
            b[m] = a[t].y;   c[m]= a[j].y;
            j++;
        }
        i = j;
        t = next[t];
    }
    if (m == 0)
      cout << -1;
    else
    {
        cout << m << endl;
        FOR (i, 1, m)
          cout << b[i] << " " <<c[i] << endl;
    }
}

int main()
{
    //openfile();
    readfile();
    process();
}


 #include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll,int> pli;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <string> vs;

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPD(i, n) for (int i = n; i > 0; i--)
#define memset(a,b) memset(a, b, sizeof(a))
#define ll long long

const
   char  in[] = "data.inp";
   char  out[]  = "data.out";

struct  pt {
    long x, y;
};

long  n, next[100100], k, b[1000100], c[1000100], m;
pt a[100100];

void  openfile()
{
    freopen(in, "r", stdin);
    freopen(out, "w", stdout);
}

void  readfile()
{
    cin >> n >> k;
    FOR (i, 1, n)
    {
        cin >> a[i].x;
        a[i].y = i;
    }

}

bool  cmp(pt a, pt b)
{
    return(a.x < b.x);
}

void  process()
{
    sort(a + 1, a + n + 1, cmp);
    FOR (i, 2, n)
      if (a[i].x != a[i - 1].x)
        next[i - 1] = i;

    FORD (i, n - 1, 1)
      if (a[i].x == a[i + 1].x)
        next[i] = next[i + 1];

    long t = 1;
    int i = 2;
    while (i <= n)
    {
        //cout << a[t].y << " " << a[i].y << endl;

        if (a[t].x != a[i].x + 1)
          break;
          m++;
        b[m] = a[t].y;  c[m] = a[i].y;
        long j = i + 1;
        int sl = 1;
        while (a[j].x == a[i].x)
        {
            if (sl == k)
            {
                t++;
                sl = 0;
            }

            sl++;
            //cout << a[t].y << " " << a[j].y << endl;
            m++;
            b[m] = a[t].y;   c[m]= a[j].y;
            j++;
        }
        i = j;
        t = next[t];
    }
    if (m == 0)
      cout << -1;
    else
    {
        cout << m << endl;
        FOR (i, 1, m)
          cout << b[i] << " " <<c[i] << endl;
    }
}

int main()
{
  //  openfile();
    readfile();
    process();
}


 #include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll,int> pli;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <string> vs;

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPD(i, n) for (int i = n; i > 0; i--)
#define memset(a,b) memset(a, b, sizeof(a))
#define ll long long

const
   char  in[] = "data.inp";
   char  out[]  = "data.out";

struct  pt {
    long x, y;
};

long  n, next[100100], k, b[1000100], c[1000100], m;
pt a[100100];

void  openfile()
{
    freopen(in, "r", stdin);
    freopen(out, "w", stdout);
}

void  readfile()
{
    cin >> n >> k;
    FOR (i, 1, n)
    {
        cin >> a[i].x;
        a[i].y = i;
    }

}

bool  cmp(pt a, pt b)
{
    return(a.x < b.x);
}

void  process()
{
    k--;
    sort(a + 1, a + n + 1, cmp);

    FOR (i, 2, n)
      if (a[i].x != a[i - 1].x)
        next[i - 1] = i;

    FORD (i, n - 1, 1)
      if (a[i].x == a[i + 1].x)
        next[i] = next[i + 1];

    long t = 1;
    int i = 2;
    while (i <= n)
    {
        //cout << a[t].y << " " << a[i].y << endl;

          m++;
        b[m] = a[t].y;  c[m] = a[i].y;

        long j = i + 1;
        int sl = 1;
        if (a[t].x == 0)
          sl = 0;
        if (sl == k)
            t++;

        if (a[t].x != a[i].x - 1)
        {
          m = 0;
          break;
        }
        while (a[j].x == a[i].x)
        {

            if (sl == k)
            {
                t++;
                sl = 0;
            }

            sl++;
            //cout << a[t].y << " " << a[j].y << endl;
            m++;
            b[m] = a[t].y;   c[m]= a[j].y;
            j++;
        }
        i = j;
        t = next[t];
    }
    if (m == 0)
      cout << -1;
    else
    {
        cout << m << endl;
        FOR (i, 1, m)
          cout << b[i] << " " <<c[i] << endl;
    }
}

int main()
{
    //openfile();
    readfile();
    process();
}


 #include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll,int> pli;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <string> vs;

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPD(i, n) for (int i = n; i > 0; i--)
#define memset(a,b) memset(a, b, sizeof(a))
#define ll long long

const
   char  in[] = "data.inp";
   char  out[]  = "data.out";

struct  pt {
	long x, y;
};

long  n, next[100100], k, b[1000100], c[1000100], m;
pt a[100100];

void  openfile()
{
	freopen(in, "r", stdin);
	freopen(out, "w", stdout);
}

void  readfile()
{
	cin >> n >> k;
	FOR (i, 1, n)
	{
		cin >> a[i].x;
		a[i].y = i;
	}

}

bool  cmp(pt a, pt b)
{
	return(a.x < b.x);
}

void  process()
{
	//k--;
	sort(a + 1, a + n + 1, cmp);

	FOR (i, 2, n)
	  if (a[i].x != a[i - 1].x)
	    next[i - 1] = i;

	FORD (i, n - 1, 1)
	  if (a[i].x == a[i + 1].x)
	    next[i] = next[i + 1];

	long t = 1;
	int i = 2;
	while (i <= n)
	{
		//cout << a[t].y << " " << a[i].y << endl;

		m++;
		b[m] = a[t].y;  c[m] = a[i].y;

		long j = i + 1;
		int sl = 1;
		if (a[t].x == 0)
		  sl = 0;
		if (sl == k)
			t++;
		if (a[t].x != a[i].x - 1)
		{
		  m = 0;
		  break;
		}
		while (a[j].x == a[i].x)
		{
			if (sl == k)
			{
				t++;
				sl = 0;
			}
			sl++;

			//cout << a[t].y << " " << a[j].y << endl;
			m++;
			b[m] = a[t].y;   c[m]= a[j].y;
			j++;
		}
		i = j;
		t = next[t];
	}
	if (m == 0)
	  cout << -1;
	else
	{
		cout << m << endl;
		FOR (i, 1, m)
		  cout << b[i] << " " <<c[i] << endl;
	}
}

int main()
{
	//openfile();
	readfile();
	process();
}


#include<bits/stdc++.h>
using namespace std;
int l;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
	int n,i,d,j;
	int k;
	scanf("%d",&n);
	scanf("%d",&k);
	vector<pair<int,int> > v,ans;
	for(i=0;i<n;i++)
	{
	  scanf("%d",&d);
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	vector<int> vv;
	for(i=0;i<v.size();i++)vv.push_back(v[i].first);
	long int should_be=1;
	int d_be=0;
	vector<int> to_add;
	to_add.clear();
	int doing =0;
	while(v.size()!=0)
	{
      int present=upper_bound(vv.begin(),vv.end(),d_be)-lower_bound(vv.begin(),vv.end(),d_be);
      if(present>should_be || present==0)
      {
        cout<<"-1";
        return 0;
      }
      if(to_add.size()==0)
      {
        to_add.push_back(v[0].second);
        should_be=k;
        l=0;
        to_add.push_back(-1);
      }
      else
      {
        i=0;
        while(i<present)
        {
          int temp;
          if(doing==0){temp=k;doing=1;}
          else temp=k-1;
          for(j=0;j<temp;j++)
          {
            ans.push_back(make_pair(to_add[l],v[i].second));
            to_add.push_back(v[i].second);
            i++;
            if(i==present)break;
          }
          if(i==present)break;
          l++;
        }
        while(to_add[l]!=-1)l++;
        l++;
        to_add.push_back(-1);
        long int ttt=k-1,mmm=present;
        should_be=(mmm*(ttt));
      }
      d_be++;
      v.erase(v.begin(),v.begin()+present);
      vv.erase(vv.begin(),vv.begin()+present);
      if(v.size()==0)break;
	}
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();i++)
	printf("%d %d\n",ans[i].first+1,ans[i].second+1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int l=0;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
	int n,i,d,j;
	int k;
	cin>>n>>k;
	vector<pair<int,int> > v,ans;
	for(i=0;i<n;i++)
	{
	  cin>>d;
	  v.push_back(make_pair(d,i));
	}
	sort(v.begin(),v.end());
	vector<int> vv;
	for(i=0;i<v.size();i++)vv.push_back(v[i].first);
	long int should_be=1;
	int d_be=0;
	vector<int> to_add;
	int doing =0;
	while(!v.empty())
	{
      int present=upper_bound(vv.begin(),vv.end(),d_be)-lower_bound(vv.begin(),vv.end(),d_be);
      if(present>should_be || !present)
      {
        cout<<"-1";
        return 0;
      }
      if(!to_add.size())
      {
        to_add.push_back(v[0].second);
        should_be=k;
        l=0;
        to_add.push_back(-1);
      }
      else
      {
        i=0;
        while(i<present)
        {
          int temp;
          if(doing==0){temp=k;doing=1;}
          else temp=k-1;
          for(j=0;j<temp;j++)
          {
            ans.push_back(make_pair(to_add[l],v[i].second));
            to_add.push_back(v[i].second);
            i++;
            if(i==present)break;
          }
          l++;
        }
        while(to_add[l]!=-1)l++;
        l++;
        to_add.push_back(-1);
        should_be=(long int)(present*(k-1));
      }
      d_be++;
      v.erase(v.begin(),v.begin()+present);
      vv.erase(vv.begin(),vv.begin()+present);
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
	return 0;
}