#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <string>
#include <time.h>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
typedef long long ll;
const int maxn=1008100;
vector<int> a[1000005];
vector<pair<int, int> > b;
int main()
{
	ll n,m,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<=n;i++)a[i].clear();
	b.clear();
	for(int i=0;i<n;++i)
	{
		int d;
		scanf("%d",&d);
		a[d].push_back(i);
	}
	if(a[0].size()!=1)
	{
		printf("-1\n");
		return 0;
	}
	int flag=0;
	for(int i=1;i<n;++i)
	{
		if(a[i].size()>a[i-1].size()*k)
		{
			flag=1;
			break;
		}
		for(int j=0;j<a[i].size();++j)
		b.push_back(make_pair(a[i][j],a[i-1][j/k]));
		if(i==1)--k;
	}
	if(flag)printf("-1\n");
	else
	{
		printf("%d\n",b.size());
		for(int i=0;i<b.size();i++)
		printf("%d %d\n",b[i].first+1,b[i].second+1);
	}
return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
type a[10000];
vector< pair<int, int> > ans;
vector<int> dp[100001];
int dp2[100001];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
	}
	if(dp[0].size()>1)
	{
		SO(-1);
		return 0;
	}
	int counter = 0, index=0;
	F(i,1,n+1)
	{
		int index = i-1;
		F(j,0,dp[i].size())
		{
			if(dp2[dp[index][counter]]>k)
				counter++;
			dp2[counter]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
vector< pair<int, int> > ans;
vector<int> dp[10000001];
int dp2[v5+5];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
		c=max(a,c);
	}
	if( (n > 1 && k==0) || dp[0].size()>1)
	{
		SO(-1);
		return 0;
	}
	if(n == 1 && c==0)
	{
		SO(0);
		return 0;
	}
	F(i,1,c+1)
	{
		int index = i-1, counter=0;
		F(j,0,dp[i].size())
		{
			if(counter >= dp[index].size())
			{
				SO(-1);
				return 0;
			}
			dp2[dp[index][counter]]++;
			dp2[dp[i][j]]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
			if(dp2[dp[index][counter]]>k-1)
				counter++;
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
vector< pair<int, int> > ans;
vector<int> dp[10000001];
int dp2[v5+5];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	int l=0;
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
		c=max(a,c);
		if(a==0)
			l=1;
	}
	if( (n > 1 && k==0) || dp[0].size()>1 || l==0)
	{
		SO(-1);
		return 0;
	}
	if(n == 1 && c==0)
	{
		SO(0);
		return 0;
	}
	F(i,1,c+1)
	{
		int index = i-1, counter=0;
		F(j,0,dp[i].size())
		{
			while(dp2[dp[index][counter]]>k-1)
				counter++;
			if(counter >= dp[index].size())
			{
				SO(-1);
				return 0;
			}
			dp2[dp[index][counter]]++;
			dp2[dp[i][j]]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
vector< pair<int, int> > ans;
vector<int> dp[10000001];
int dp2[v5+5];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
		c=max(a,c);
	}
	if( (n > 1 && k==0) || dp[0].size()>1)
	{
		SO(-1);
		return 0;
	}
	if(n == 1)
	{
		if(c==0)
			SO(0);
		else
			SO(-1);
		return 0;
	}
	F(i,1,c+1)
	{
		int index = i-1, counter=0;
		F(j,0,dp[i].size())
		{
			if(dp2[dp[index][counter]]>k-1)
				counter++;
			if(counter >= dp[index].size())
			{
				SO(-1);
				return 0;
			}
			dp2[dp[index][counter]]++;
			dp2[dp[i][j]]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
vector< pair<int, int> > ans;
vector<int> dp[10000001];
int dp2[v5+5];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
		c=max(a,c);
	}
	if(k==0 || dp[0].size()>1)
	{
		SO(-1);
		return 0;
	}
	F(i,1,c+1)
	{
		int index = i-1, counter=0;
		F(j,0,dp[i].size())
		{
			if(dp2[dp[index][counter]]>k-1)
				counter++;
			if(counter >= dp[index].size())
			{
				SO(-1);
				return 0;
			}
			dp2[dp[index][counter]]++;
			dp2[dp[i][j]]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
type a[10000];
vector< pair<int, int> > ans;
vector<int> dp[100001];
int dp2[100001];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
	}
	if(k==0 || dp[0].size()>1)
	{
		SO(-1);
		return 0;
	}
	F(i,1,dp.size())
	{
		int index = i-1, counter=0;
		F(j,0,dp[i].size())
		{
			if(dp2[dp[index][counter]]>k-1)
				counter++;
			if(counter >= dp[index].size())
			{
				SO(-1);
				return 0;
			}
			dp2[dp[index][counter]]++;
			dp2[dp[i][j]]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
type a[10000];
vector< pair<int, int> > ans;
vector<int> dp[100001];
int dp2[100001];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
	}
	if(dp[0].size()>1)
	{
		SO(-1);
		return 0;
	}
	F(i,1,n+1)
	{
		int index = i-1, counter=0;
		F(j,0,dp[i].size())
		{
			if(dp2[dp[index][counter]]>k)
				counter++;
			dp2[counter]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
type a[10000];
vector< pair<int, int> > ans;
vector<int> dp[100001];
int dp2[100001];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
	}
	if(k==0 || dp[0].size()>1)
	{
		SO(-1);
		return 0;
	}
	F(i,1,n+1)
	{
		int index = i-1, counter=0;
		F(j,0,dp[i].size())
		{
			if(dp2[dp[index][counter]]>k-1)
				counter++;
			if(counter >= dp[index].size())
			{
				SO(-1);
				return 0;
			}
			dp2[dp[index][counter]]++;
			dp2[dp[i][j]]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
vector< pair<int, int> > ans;
vector<int> dp[10000001];
int dp2[v5+5];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
		c=max(a,c);
	}
	if( (n > 1 && k==0) || dp[0].size()>1)
	{
		SO(-1);
		return 0;
	}
	if(n == 1 && c==0)
	{
		SO(0);
		return 0;
	}
	F(i,1,c+1)
	{
		int index = i-1, counter=0;
		F(j,0,dp[i].size())
		{
			if(counter >= dp[index].size())
			{
				SO(-1);
				return 0;
			}
			dp2[dp[index][counter]]++;
			dp2[dp[i][j]]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
			if(dp2[dp[index][counter]]>=k)
				counter++;
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
vector< pair<int, int> > ans;
vector<int> dp[10000001];
int dp2[v5+5];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
		c=max(a,c);
	}
	if( (n > 1 && k==0) || dp[0].size()>1)
	{
		SO(-1);
		return 0;
	}
	if(n == 1 && c==0)
	{
		SO(0);
		return 0;
	}
	F(i,1,c+1)
	{
		int index = i-1, counter=0;
		F(j,0,dp[i].size())
		{
			if(dp2[dp[index][counter]]>k-1)
				counter++;
			if(counter >= dp[index].size())
			{
				SO(-1);
				return 0;
			}
			dp2[dp[index][counter]]++;
			dp2[dp[i][j]]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
type a[10000];
vector< pair<int, int> > ans;
vector<int> dp[100001];
int dp2[100001];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
	}
	if(k==0 || dp[0].size()>1)
	{
		SO(-1);
		return 0;
	}
	F(i,1,n+1)
	{
		int index = i-1, counter=0;
		F(j,0,dp[i].size())
		{
			if(dp2[dp[index][counter]]>k)
				counter++;
			if(counter >= dp[index].size())
			{
				SO(-1);
				return 0;
			}
			dp2[dp[index][counter]]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
type a[10000];
vector< pair<int, int> > ans;
vector<int> dp[10000001];
int dp2[100001];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
		c=max(a,c);
	}
	if(k==0 || dp[0].size()>1)
	{
		SO(-1);
		return 0;
	}
	F(i,1,c+1)
	{
		int index = i-1, counter=0;
		F(j,0,dp[i].size())
		{
			if(dp2[dp[index][counter]]>k-1)
				counter++;
			if(counter >= dp[index].size())
			{
				SO(-1);
				return 0;
			}
			dp2[dp[index][counter]]++;
			dp2[dp[i][j]]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
vector< pair<int, int> > ans;
vector<int> dp[10000001];
int dp2[v5+5];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	int l=0;
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
		c=max(a,c);
		if(a==0)
			l=1;
	}
	if( (n > 1 && k==0) || dp[0].size()>1 || l==0)
	{
		SO(-1);
		return 0;
	}
	if(n == 1 && c==0)
	{
		SO(0);
		return 0;
	}
	F(i,1,c+1)
	{
		if(dp[i-1].size() == 0)
		{
			SO(-1);
			return 0;
		}
		int index = i-1, counter=0;
		F(j,0,dp[i].size())
		{
			while(dp2[dp[index][counter]]>k-1)
				counter++;
			if(counter >= dp[index].size())
			{
				SO(-1);
				return 0;
			}
			dp2[dp[index][counter]]++;
			dp2[dp[i][j]]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
type a[10000];
vector< pair<int, int> > ans;
vector<int> dp[100001];
int dp2[100001];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
	}
	if(dp[0].size()>1)
	{
		SO(-1);
		return 0;
	}
	F(i,1,n+1)
	{
		int index = i-1, counter=0;
		F(j,0,dp[i].size())
		{
			if(dp2[dp[index][counter]]>k)
				counter++;
			if(counter >= dp[index].size())
			{
				SO(-1);
				return 0;
			}
			dp2[dp[index][counter]]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
vector< pair<int, int> > ans;
vector<int> dp[10000001];
int dp2[v5+5];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	int l=0;
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
		c=max(a,c);
		if(a==0)
			l=1;
	}
	if( (n > 1 && k==0) || dp[0].size()>1 || l==0)
	{
		SO(-1);
		return 0;
	}
	if(n == 1 && c==0)
	{
		SO(0);
		return 0;
	}
	F(i,1,c+1)
	{
		int index = i-1, counter=0;
		F(j,0,dp[i].size())
		{
			if(dp2[dp[index][counter]]>k-1)
				counter++;
			if(counter >= dp[index].size())
			{
				SO(-1);
				return 0;
			}
			dp2[dp[index][counter]]++;
			dp2[dp[i][j]]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>
#include <fstream>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(i,a,n) for(long int i=(a); i<(n); ++i)
#define FLL(i,a,n) for(long long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long long int i=(a);i>=(n);--i)
#define REP(i, a, n) for(i=(a); i<(n); ++i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define BINSTR(num) bitset<64>((num)).to_string();

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"

#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())

#define fr first
#define se second

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

/*
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

#define debug(x, sz) F(i,0,sz){cout<<x[i]<<" ";}cout<<"\n"

#define type int

inline type ABS(type a) { if ( a < 0 ) return (-a); return a; }
inline type min(type a,type b,type c){return min(a,min(b,c));}
inline type max(type a,type b,type c){return max(a,max(b,c));}
inline type powmod(type x,type n, type _mod){type res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline type gcd(type a,type b){type t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline type lcm(type a,type b){return a/(gcd(a,b)*b);}

const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)

//CODE STARTS HERE

type n, m,k, c = 0;
vector< pair<int, int> > ans;
vector<int> dp[10000001];
int dp2[v5+5];

inline void cinarr(type x[], type n){for(type i=0; i<(n); ++i)SI(x[i]);}
inline void cinvec(vector<type> &arr, type n){for(type i=0; i<(n); ++i){type x;SI(x);arr.pb(x);};}

int main()
{
	FASTER;
	DI(n,k);
	F(i,1,1+n)
	{
		int a;
		SI(a);
		dp[a].pb(i);
		c=max(a,c);
	}
	if( (n > 1 && k==0) || dp[0].size()>1)
	{
		SO(-1);
		return 0;
	}
	if(n == 1 && c==0)
	{
		SO(0);
		return 0;
	}
	F(i,1,c+1)
	{
		int index = i-1, counter=0;
		F(j,0,dp[i].size())
		{
			if(counter >= dp[index].size())
			{
				SO(-1);
				return 0;
			}
			dp2[dp[index][counter]]++;
			dp2[dp[i][j]]++;
			ans.pb(mp(dp[index][counter], dp[i][j]));
			if(dp2[dp[index][counter]]>k)
				counter++;
		}
	}
	SO(ans.size());
	F(i,0,ans.size())
		cout<<ans[i].fr<<" "<<ans[i].se<<endl;
	return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};
Node graph[100010];

class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist>0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;int u = 1;
    while (h < n)
    {
        if ((h > 0) && (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if (temp > cur * k - cur +u) {printf("-1\n");return;}
        else cur = temp;
if (u == 1) u--;
        h++;
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;if (last == 0) tot = 0; else tot = 1;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {if (last == 0) tot = 0; else tot = 1;last++; }
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};
Node graph[100010];

class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist>0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;
    while (h < n)
    {
        if ((h > 0) && (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if (temp > cur * k - cur) {printf("-1\n");return;}
        else cur = temp;

        h++;
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;if (last == 0) tot = 0; else tot = 1;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {if (last == 0) tot = 0; else tot = 1;last++; }
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};

class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    Node graph[n];
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist>0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;
    while (h < n)
    {
        if ((h == 0) || (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if (temp > cur * kk) {printf("-1\n");return;}
        else cur = temp;
        if (graph[h].Dist == 1) kk--;
        h++;
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;if (last == 0) tot = 0; else tot = 1;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {if (last == 0) tot = 0; else tot = 1;last++; }
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};
Node graph[100010];

class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist>0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;int u = 1;
    while (h < n)
    {
        if ((h > 0) && (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if (temp > cur * k - cur +u) {printf("-1\n");return;}
        else cur = temp;
        if (graph[h].Dist == 1) u--;
        h++;
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;if (last == 0) tot = 0; else tot = 1;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {if (last == 0) tot = 0; else tot = 1;last++; }
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};

class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    Node graph[n];
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist>0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;
    while (h < n)
    {
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if (temp > cur * kk) {printf("-1\n");return;}
        else cur = temp;
        if (h == 0) kk--;
        h++;
        if ((h < n) && (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {last++; if (last == 0) tot = 0; else tot = 1;}
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};

class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    Node graph[n];
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist>0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;
    while (h < n)
    {
        if ((h > 0) && (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if (temp > cur * kk) {printf("-1\n");return;}
        else cur = temp;
        if (graph[h].Dist == 1) kk--;
        h++;
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;if (last == 0) tot = 0; else tot = 1;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {if (last == 0) tot = 0; else tot = 1;last++; }
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};
Node graph[100010];

class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist != 0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;int u = 1;
    while (h < n)
    {
        if ((h > 0) && (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if ((long long) temp > (long long)cur * (long long)k - (long long)cur +(long long)u) {printf("-1\n");return;}
        else cur = temp;
        if (graph[h].Dist == 1) u--;
        h++;
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;if (last == 0) tot = 0; else tot = 1;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {if (last == 0) tot = 0; else tot = 1;last++; }
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};

class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    Node graph[n];
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist>0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;
    while (h < n)
    {
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if (temp > cur * kk) {printf("-1\n");return;}
        else cur = temp;
        if (graph[h].Dist == 0) kk--;
        h++;
        if ((h < n) && (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;if (last == 0) tot = 0; else tot = 1;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {if (last == 0) tot = 0; else tot = 1;last++; }
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};
    Node graph[100000];
class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist>0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;
    while (h < n)
    {
        if ((h > 0) && (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if (temp > cur * kk) {printf("-1\n");return;}
        else cur = temp;
        if (graph[h].Dist == 1) kk--;
        h++;
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;if (last == 0) tot = 0; else tot = 1;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {if (last == 0) tot = 0; else tot = 1;last++; }
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};

class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    Node graph[n];
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist>0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;
    while (h < n)
    {
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if (temp > cur * kk) {printf("-1\n");return;}
        else cur = temp;
        if (graph[h].Dist == 1) kk--;
        h++;
        if ((h < n) && (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {last++; if (last == 0) tot = 0; else tot = 1;}
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
    Node graph[100000];

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};

class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist>0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;
    while (h < n)
    {
        if ((h > 0) && (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if (temp > cur * kk) {printf("-1\n");return;}
        else cur = temp;
        if (graph[h].Dist == 1) kk--;
        h++;
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;if (last == 0) tot = 0; else tot = 1;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {if (last == 0) tot = 0; else tot = 1;last++; }
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};

class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    Node graph[n];
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist>0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;
    while (h < n)
    {
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            //if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if (temp > cur * kk) {printf("-1\n");return;}
        else cur = temp;
        if (graph[h].Dist == 1) kk--;
        h++;
        if ((h < n) && (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;if (last == 0) tot = 0; else tot = 1;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {if (last == 0) tot = 0; else tot = 1;last++; }
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};

class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    Node graph[n];
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist>0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;
    while (h < n)
    {
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if (temp > cur * kk) {printf("-1\n");return;}
        else cur = temp;
        if (graph[h].Dist == 1) kk--;
        h++;
        if ((h < n) && (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {if (last == 0) tot = 0; else tot = 1;last++; }
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};

class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    Node graph[n];
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist>0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;
    while (h < n)
    {
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if (temp > cur * kk) {printf("-1\n");return;}
        else cur = temp;
        if (graph[h].Dist == 1) kk--;
        h++;
        if ((h < n) && (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;if (last == 0) tot = 0; else tot = 1;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {if (last == 0) tot = 0; else tot = 1;last++; }
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};

class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    Node graph[n];
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist>0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;
    while (h < n)
    {
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if (temp > cur * kk) {printf("-1\n");return;}
        else cur = temp;
        if (graph[h].Dist == 1) kk--;
        h++;
        //if ((h < n) && (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;if (last == 0) tot = 0; else tot = 1;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {if (last == 0) tot = 0; else tot = 1;last++; }
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node
{
    int Pos, Dist;
    bool operator<(Node b) const
    {
        return Dist < b.Dist;
    }
};
Node graph[100010];

class Solution
{
public:
void RecoverGraph(int Dist[], int n, int k)
{
    for (int i = 0; i < n; i++)
    {
        graph[i].Pos = i + 1;
        graph[i].Dist = Dist[i];
    }
    sort(graph, graph + n);
    if (graph[0].Dist>0) {printf("-1\n");return;}
    int cur = 0, h = 0;int kk = k;int u = 1;
    while (h < n)
    {
        if ((h > 0) && (graph[h].Dist - 1 != graph[h - 1].Dist)) {printf("-1\n");return;}
        int temp = 1;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) {h++; temp++;}
        if (cur == 0)
        {
            if (temp != 1) {printf("-1\n");return;}
            cur = temp;
        } else
        if (temp > cur * k - cur +u) {printf("-1\n");return;}
        else cur = temp;
        if (graph[h].dist == 1) u--;
        h++;
    }
    int last = 0; h = 1;
    printf("%d\n", n - 1);
    while (h < n)
    {
        int hh = h;
        while ((h + 1 < n) && (graph[h].Dist == graph[h + 1].Dist)) h++;
        int tot = 0;if (last == 0) tot = 0; else tot = 1;
        for (int i = hh; i <= h; i++)
        {
            printf("%d %d\n", graph[i].Pos, graph[last].Pos);
            tot++;
            if (tot == k) {if (last == 0) tot = 0; else tot = 1;last++; }
        }
        last = hh;h++;
    }
}
};

int dist[100000];
int main()
{
    int n, k;scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &dist[i]);
    Solution ans;
    ans.RecoverGraph(dist, n, k);
    return 0;
}


/**
 *    @author     : Maruf Tuhin
 *    @School     : CUET CSE 11
 *    @Topcoder   : the_redback
 *    @CodeForces : the_redback
 *    @UVA        : the_redback
 *    @link       : maruf.2hin@gmail.com
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<stack>
using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define pp pop_back
#define inf 10000000
#define NN 100010

struct D
{
    int p,v;
};

D a[NN];

bool comp(D c,D b)
{
    return c.v<b.v;
}

int viw[NN];
int par[NN];
vector<int>e[NN];

main()
{
    ios_base::sync_with_stdio(false);
    int t,tc;
    int i,j,k,l;
    int res,u,w,p,n,x,y,z,m,q,r,v;
    D data;
    //cin>>tc;
    while(cin>>n>>k)
    {
        mem(viw,0);
        int MAX=-inf;
        for(i=0;i<n;i++)
        {
            cin>>r;
            data.p=i;
            data.v=r;
            a[i]=data;
            viw[r]++;
            MAX=max(r,MAX);
            if(r==0)
                par[r]=i;
        }
        int ret=0,flag=1;
        for(i=0;i<=MAX && ret<n && flag;i++)
        {
            if(viw[i]!=0)
                ret+=viw[i];
            if(viw[i]>1 && i==0)
                flag=0;
            if(viw[i]>k)
                flag=0;
            if(viw[i]==0)
                flag=0;
        }
        if(flag==0)
        {
            printf("-1\n");
            continue;
        }
        sort(a,a+n,comp);
        ret=0;
        for(i=1;i<n;i++)
        {
            v=a[i].v;
            p=a[i].p;
            e[p].pb(par[v-1]);
            par[v]=p;
            ret++;
        }
        printf("%d\n",ret);
        for(i=0;i<n;i++)
        {
            for(j=0;j<e[i].size();i++)
                printf("%d %d\n",i+1,e[i][j]+1);
        }
    }
    return 0;
}


/**
 *    @author     : Maruf Tuhin
 *    @School     : CUET CSE 11
 *    @Topcoder   : the_redback
 *    @CodeForces : the_redback
 *    @UVA        : the_redback
 *    @link       : maruf.2hin@gmail.com
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<stack>
using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define pp pop_back
#define inf 10000000
#define NN 100010

struct D
{
    int p,v;
};

D a[NN];

bool comp(D c,D b)
{
    return c.v<b.v;
}

int viw[NN];
vector<int>e[NN];
vector<int>vv[NN];

main()
{
    ios_base::sync_with_stdio(false);
    int t,tc;
    int i,j,k,l;
    int res,u,w,p,n,x,y,z,m,q,r,v,zero;
    D data;
    //cin>>tc;
    while(cin>>n>>k)
    {
        mem(viw,0);
        int MAX=-inf;
        for(i=0; i<n; i++)
        {
            cin>>r;
            data.p=i;
            data.v=r;
            a[i]=data;
            viw[r]++;
            vv[r].pb(i);
            if(r==0)
                zero=i;
            MAX=max(r,MAX);
        }
        int ret=0,flag=1;
        if(viw[0]!=1)
        {
            printf("-1\n");
            continue;
        }

        sort(a,a+n,comp);
        ret=0;
        for(i=0; i<n; i++)
        {
            if(i==zero)
                viw[i]=k;
            else
                viw[i]=k-1;
        }
        for(i=1; i<n; i++)
        {
            v=a[i].v;
            p=a[i].p;
            flag=1;
            // viw[p]--;
            for(j=0; j<vv[v-1].size() && flag; j++)
            {
                l=vv[v-1][j];
                if(viw[l]>0)
                {
                    viw[l]--;
                    flag=0;
                }
            }
            if(flag==1)
            {
                printf("-1");
                return 0;
            }
            e[p].pb(l);
            ret++;
        }
        printf("%d\n",ret);
        for(i=0; i<n; i++)
        {
            for(j=0; j<e[i].size(); j++)
                printf("%d %d\n",i+1,e[i][j]+1);
        }
    }
    return 0;
}


/**
 *    @author     : Maruf Tuhin
 *    @School     : CUET CSE 11
 *    @Topcoder   : the_redback
 *    @CodeForces : the_redback
 *    @UVA        : the_redback
 *    @link       : maruf.2hin@gmail.com
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<stack>
using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define pp pop_back
#define inf 10000000
#define NN 100010

struct D
{
    int p,v;
};

D a[NN];

bool comp(D c,D b)
{
    return c.v<b.v;
}

int viw[NN];
vector<int>e[NN];
vector<int>vv[NN];

main()
{
    ios_base::sync_with_stdio(false);
    int t,tc;
    int i,j,k,l;
    int res,u,w,p,n,x,y,z,m,q,r,v;
    D data;
    //cin>>tc;
    while(cin>>n>>k)
    {
        mem(viw,0);
        int MAX=-inf;
        for(i=0; i<n; i++)
        {
            cin>>r;
            data.p=i;
            data.v=r;
            a[i]=data;
            viw[r]++;
            vv[r].pb(i);
            MAX=max(r,MAX);
        }
        int ret=0,flag=1;
        for(i=0; i<=MAX && ret<n && flag; i++)
        {
            if(i==0)
            {
                if(viw[i]!=1)
                    flag=0;
            }
            else
            {
                if(viw[i]!=0)
                    ret+=viw[i];
                if(viw[i]>(k*viw[i-1]))
                    flag=0;
                if(viw[i]==0)
                    flag=0;
            }
        }
        if(flag==0)
        {
            printf("-1\n");
            continue;
        }
        sort(a,a+n,comp);
        ret=0;
        mem(viw,0);
        for(i=1; i<n; i++)
        {
            v=a[i].v;
            p=a[i].p;
            flag=1;
            for(j=0;j<vv[v-1].size() && flag;j++)
            {
                l=vv[v-1][j];
                if(viw[l]<k)
                {
                    viw[l]++;
                    flag=0;
                }
            }
            if(flag==1)
            {
                printf("-1");
                return 0;
            }
            e[p].pb(l);
            ret++;
        }
        printf("%d\n",ret);
        for(i=0; i<n; i++)
        {
            for(j=0; j<e[i].size(); i++)
                printf("%d %d\n",i+1,e[i][j]+1);
        }
    }
    return 0;
}