#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<vector>
#include<cstring>
#include<string>
#include<limits>
#include<set>

using namespace std;

#define M 100010
#define N 1010
#define mod 1000000007
#define pi acos(-1.0)
#define inf (1<<30)
#define ls p<<1
#define rs p<<1|1
//#pragma comment(linker, "/STACK:102400000")
typedef long long ll;

int n, m;
vector<int> vec[M];
vector<int> vv[M];
int x[M], y[M];
set<int> st;

bool can( int u, int v )
{
    for( int i = 0; i < vec[u].size(); ++i )
        if( vec[u][i] == v ) return 0;
    return 1;
}
void get( int u )
{
    int cnt = 0;
    set<int>::iterator it = st.begin();
    vv[u].clear();
    while( it != st.end() ){
        vv[u].push_back( *it );
        it++;
        cnt++;
        if( cnt > 10 ) break;
    }
}
int dfs( int dep, int u )
{
    if( dep == m ){
        return 1;
    }
    st.erase( u );

    int v;
    get( u );
    for( int i = 0; i < vv[u].size(); ++i ){
        v = vv[u][i];
        if( can( u, v ) ){
            x[dep] = u, y[dep] = v;
            if( dfs( dep+1, v ) ) return 1;
        }
    }

    if( n == m && dep == n-1 ){
        if( can( u, 1 ) ){
            x[dep] = u, y[dep] = 1;
            return 1;
        }
    }
    st.insert( u );
    return 0;
}

bool check()
{
    for( int i = 1; i <= n; ++i ) st.insert( i );
    //int u = 1;

    return dfs( 0, 1 );
}
int main()
{
   // #ifndef ONLINE_JUDGE
    //    freopen( "a.in", "r", stdin );
   // #endif // ONLINE_JUDGE
    cin>>n>>m;
    int u, v;
    for( int i = 0; i < m; ++i ){
        scanf( "%d%d", &u, &v );
        vec[u].push_back( v );
        vec[v].push_back( u );
    }
    if( check() ){
        for( int i = 0; i < m; ++i ) printf( "%d %d\n", x[i], y[i] );
    }
    else puts( "-1" );
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<vector>
#include<cstring>
#include<string>
#include<limits>
#include<set>

using namespace std;

#define M 100010
#define N 1010
#define mod 1000000007
#define pi acos(-1.0)
#define inf (1<<30)
#define ls p<<1
#define rs p<<1|1
//#pragma comment(linker, "/STACK:102400000")
typedef long long ll;

int n, m;
vector<int> vec[M];
vector<int> vv[M];
int x[M], y[M];
int in[M];
bool check()
{
    int cnt = 0;
    queue<int> q;
    for( int i = 1; i <= n; ++i ) q.push( i );

    int u, v;
    for( int i = 1; i <= n; ++i )if( in[i] < 2 ){
        for( int j = 0; !q.empty() && j < 10; ){
            v = q.front(); q.pop();
            if( in[v] >= 2 ) continue;
            if( v == i ){
                q.push( v );
                ++j;
                continue;
            }
            int c = 0;
            for( int l = 0; l < vec[i].size(); ++l )
                if( vec[i][l] == v ){
                    c = 1;
                    if( in[v] < 2 )
                        q.push( v );
                    break;
                }
            for( int l = 0; l < vv[i].size(); ++l )
                if( vv[i][l] == v ){
                    c = 1;
                    if( in[v] < 2 )
                        q.push( v );
                    break;
                }

            if( c ){
                ++j;
                continue;

            }
            in[i]++;
            in[v]++;
            vv[i].push_back( v );
            vv[v].push_back( i );
            x[cnt] = i, y[cnt++] = v;
            if( cnt == m ) return 1;
            if( in[v] < 2 ) q.push( v );
            if( in[i] == 2 ) break;
            ++j;
        }
    }
    return 0;
}
int main()
{
   // #ifndef ONLINE_JUDGE
    //    freopen( "a.in", "r", stdin );
   // #endif // ONLINE_JUDGE
    cin>>n>>m;
    int u, v;
    for( int i = 0; i < m; ++i ){
        scanf( "%d%d", &u, &v );
        vec[u].push_back( v );
        vec[v].push_back( u );
    }
    if( check() ){
        for( int i = 0; i < m; ++i ) printf( "%d %d\n", x[i], y[i] );
    }
    else puts( "-1" );
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<vector>
#include<cstring>
#include<string>
#include<limits>
#include<set>

using namespace std;

#define M 100010
#define N 1010
#define mod 1000000007
#define pi acos(-1.0)
#define inf (1<<30)
#define ls p<<1
#define rs p<<1|1
//#pragma comment(linker, "/STACK:102400000")
typedef long long ll;

int n, m;
vector<int> vec[M];
vector<int> vv[M];
int x[M], y[M];
int in[M];
bool check()
{
    int cnt = 0;
    queue<int> q;
    for( int i = 1; i <= n; ++i ) q.push( i );

    int u, v;
    for( int i = 1; i <= n; ++i )if( in[i] < 2 ){
        int k = 1;
        for( int j = 0; !q.empty() && j < 10; ++j ){
            v = q.front(); q.pop();
            if( in[v] >= 2 ) continue;
            int c = 0;
            for( int l = 0; l < vec[i].size(); ++l )
                if( i == v || vec[i][l] == v ){
                    c = 1;
                    if( in[v] < 2 )
                        q.push( v );
                    break;
                }
            for( int l = 0; l < vv[i].size(); ++l )
                if( i == v || vv[i][l] == v ){
                    c = 1;
                    if( in[v] < 2 )
                        q.push( v );
                    break;
                }

            if( c ) continue;
            in[i]++;
            in[v]++;
            vv[i].push_back( v );
            vv[v].push_back( i );
            x[cnt] = i, y[cnt++] = v;
            if( cnt == m ) return 1;
            if( in[v] < 2 ) q.push( v );
            if( in[i] == 2 ) break;
        }
    }
    return 0;
}
int main()
{
   // #ifndef ONLINE_JUDGE
    //    freopen( "a.in", "r", stdin );
   // #endif // ONLINE_JUDGE
    cin>>n>>m;
    int u, v;
    for( int i = 0; i < m; ++i ){
        scanf( "%d%d", &u, &v );
        vec[u].push_back( v );
        vec[v].push_back( u );
    }
    if( check() ){
        for( int i = 0; i < m; ++i ) printf( "%d %d\n", x[i], y[i] );
    }
    else puts( "-1" );
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<vector>
#include<cstring>
#include<string>
#include<limits>
#include<set>

using namespace std;

#define M 100010
#define N 1010
#define mod 1000000007
#define pi acos(-1.0)
#define inf (1<<30)
#define ls p<<1
#define rs p<<1|1
//#pragma comment(linker, "/STACK:102400000")
typedef long long ll;

int n, m;
vector<int> vec[M];
vector<int> vv[M];
int x[M], y[M];
int in[M];
bool check()
{
    int cnt = 0;
    queue<int> q;
    for( int i = 1; i <= n; ++i ) q.push( i );

    int u, v;
    for( int i = 1; i <= n; ++i )if( in[i] < 2 ){
        for( int j = 0; !q.empty() && j < 100; ){
            v = q.front(); q.pop();
            if( in[v] >= 2 ) continue;
            if( v == i ){
                q.push( v );
                ++j;
                continue;
            }
            int c = 0;
            for( int l = 0; l < vec[i].size(); ++l )
                if( vec[i][l] == v ){
                    c = 1;
                    q.push( v );
                    break;
                }
            for( int l = 0; l < vv[i].size(); ++l )
                if( vv[i][l] == v ){
                    c = 1;
                    q.push( v );
                    break;
                }

            if( c ){
                ++j;
                continue;

            }
            in[i]++;
            in[v]++;
            vv[i].push_back( v );
            vv[v].push_back( i );
            x[cnt] = i, y[cnt++] = v;
            if( cnt == m ) return 1;
            if( in[v] < 2 ) q.push( v );
            if( in[i] == 2 ) break;
            ++j;
        }
    }
    return 0;
}
int main()
{
   // #ifndef ONLINE_JUDGE
    //    freopen( "a.in", "r", stdin );
   // #endif // ONLINE_JUDGE
    cin>>n>>m;
    int u, v;
    for( int i = 0; i < m; ++i ){
        scanf( "%d%d", &u, &v );
        vec[u].push_back( v );
        vec[v].push_back( u );
    }
    if( check() ){
        for( int i = 0; i < m; ++i ) printf( "%d %d\n", x[i], y[i] );
    }
    else puts( "-1" );
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<vector>
#include<cstring>
#include<string>
#include<limits>
#include<set>

using namespace std;

#define M 100010
#define N 1010
#define mod 1000000007
#define pi acos(-1.0)
#define inf (1<<30)
#define ls p<<1
#define rs p<<1|1
//#pragma comment(linker, "/STACK:102400000")
typedef long long ll;

int n, m;
vector<int> vec[M];
vector<int> vv[M];
int x[M], y[M];
set<int> st;

int in[M];
bool check1()
{
    int cnt = 0;
    queue<int> q;
    for( int i = 1; i <= n; ++i ) q.push( i );

    int u, v;
    for( int i = 1; i <= n; ++i )if( in[i] < 2 ){
        for( int j = 0; !q.empty() && j < 100; ){
            v = q.front(); q.pop();
            if( in[v] >= 2 ) continue;
            if( v == i ){
                q.push( v );
                ++j;
                continue;
            }
            int c = 0;
            for( int l = 0; l < vec[i].size(); ++l )
                if( vec[i][l] == v ){
                    c = 1;
                    q.push( v );
                    break;
                }
            for( int l = 0; l < vv[i].size(); ++l )
                if( vv[i][l] == v ){
                    c = 1;
                    q.push( v );
                    break;
                }

            if( c ){
                ++j;
                continue;

            }
            in[i]++;
            in[v]++;
            vv[i].push_back( v );
            vv[v].push_back( i );
            x[cnt] = i, y[cnt++] = v;
            if( cnt == m ) return 1;
            if( in[v] < 2 ) q.push( v );
            if( in[i] == 2 ) break;
            ++j;
        }
    }
    return 0;
}
bool can( int u, int v )
{
    for( int i = 0; i < vec[u].size(); ++i )
        if( vec[u][i] == v ) return 0;
    return 1;
}
void get( int u )
{
    int cnt = 0;
    set<int>::iterator it = st.begin();
    vv[u].clear();
    while( it != st.end() ){
        vv[u].push_back( *it );
        it++;
        cnt++;
        if( cnt > 10 ) break;
    }
}
int dfs( int dep, int u )
{
    if( dep == m ){
        return 1;
    }
    st.erase( u );

    int v;
    get( u );
    for( int i = 0; i < vv[u].size(); ++i ){
        v = vv[u][i];
        if( can( u, v ) ){
            x[dep] = u, y[dep] = v;
            if( dfs( dep+1, v ) ) return 1;
        }
    }

    if( n == m && dep == n-1 ){
        if( can( u, 1 ) ){
            x[dep] = u, y[dep] = 1;
            return 1;
        }
    }
    st.insert( u );
    return 0;
}

bool check()
{
    for( int i = 1; i <= n; ++i ) st.insert( i );
    //int u = 1;
    if( n >= 5 )
        return dfs( 0, 1 );
    else{
        return check1();
    }
}
int main()
{
   // #ifndef ONLINE_JUDGE
    //    freopen( "a.in", "r", stdin );
   // #endif // ONLINE_JUDGE
    cin>>n>>m;
    int u, v;
    for( int i = 0; i < m; ++i ){
        scanf( "%d%d", &u, &v );
        vec[u].push_back( v );
        vec[v].push_back( u );
    }
    if( check() ){
        for( int i = 0; i < m; ++i ) printf( "%d %d\n", x[i], y[i] );
    }
    else puts( "-1" );
}


#include <map>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;

const int Sn = 100010;
const int LIM = 10000000;

map<LL,int> MP;
int n, m;
int p[Sn];

int main()
{
//     freopen("cf.in" , "r", stdin);
//     freopen("cf.out", "w", stdout);
     cin >> n >> m;
     for (int i = 1, u, v; i <= m; i ++) {
	  cin >> u >> v;
	  MP[(LL)u*100001+v] = 1;
	  MP[(LL)v*100001+u] = 1;
     }
     for (int i = 1; i <= n; i ++) p[i] = i;
     for (int i = 1, a, b; i <= LIM; i ++)
	  a = rand()%n+1, b = rand()%n+1, swap(p[a], p[b]);
     for (int t = 1, a, b; t <= LIM/m; t ++) {
	  bool ok = 1;
	  for (int i = 1; i <= m; i ++)
	       if (MP[(LL)p[i]*100001+p[i+1>n?i+1-n:i+1]]) { ok = 0; break; }
	  if (!ok) {
	       for (int i = 1; i <= m; i ++)
		    a = rand()%n+1, b = rand()%n+1, swap(p[a], p[b]);
	  }
	  else {
	       for (int i = 1; i <= m; i ++)
		    printf("%d %d\n", p[i], p[i+1>n?i+1-n:i+1]);
	       return 0;
	  }
     }
     printf("-1\n");
}


#include <map>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;

const int Sn = 100010;

map<LL,int> MP;
int n, m, LIM = 10000000;
int p[Sn];

int main()
{
//     freopen("cf.in" , "r", stdin);
//     freopen("cf.out", "w", stdout);
     cin >> n >> m;
     for (int i = 1, u, v; i <= m; i ++) {
	  cin >> u >> v;
	  MP[(LL)u*100001+v] = 1;
	  MP[(LL)v*100001+u] = 1;
     }
     if (n > 10000) LIM /= 5;
     for (int i = 1; i <= n; i ++) p[i] = i;
     for (int i = 1, a, b; i <= LIM; i ++)
	  a = rand()%n+1, b = rand()%n+1, swap(p[a], p[b]);
     for (int t = 1, a, b; t <= LIM/m; t ++) {
	  bool ok = 1;
	  for (int i = 1; i <= m; i ++)
	       if (MP[(LL)p[i]*100001+p[i+1>n?i+1-n:i+1]]) { ok = 0; break; }
	  if (!ok) {
	       for (int i = 1; i <= m; i ++)
		    a = rand()%n+1, b = rand()%n+1, swap(p[a], p[b]);
	  }
	  else {
	       for (int i = 1; i <= m; i ++)
		    printf("%d %d\n", p[i], p[i+1>n?i+1-n:i+1]);
	       return 0;
	  }
     }
     printf("-1\n");
}


#include <map>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;

const int Sn = 100010;

map<LL,int> MP;
int n, m, LIM = 10000000;
int p[Sn];

int main()
{
//     freopen("cf.in" , "r", stdin);
//     freopen("cf.out", "w", stdout);
     cin >> n >> m;
     for (int i = 1, u, v; i <= m; i ++) {
	  cin >> u >> v;
	  MP[(LL)u*100001+v] = 1;
	  MP[(LL)v*100001+u] = 1;
     }
     for (int i = 1; i <= n; i ++) p[i] = i;
     for (int i = 1, a, b; i <= LIM; i ++)
	  a = rand()%n+1, b = rand()%n+1, swap(p[a], p[b]);
     for (int t = 1, a, b, pp; t <= LIM/m; t ++) {
	  bool ok = 1;
	  for (int i = 1; i <= m; i ++)
	       if (MP[(LL)p[i]*100001+p[i+1>n?i+1-n:i+1]]) { ok = 0, pp = i; break; }
	  if (!ok) swap(p[pp], p[rand()%n+1]);
	  else {
	       for (int i = 1; i <= m; i ++)
		    printf("%d %d\n", p[i], p[i+1>n?i+1-n:i+1]);
	       return 0;
	  }
     }
     printf("-1\n");
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<set>
#include<ctime>
#define N 120000
using namespace std;
int i,n,m,x,y,p[N];
set <int> s[N];

int xx[N] , yy[N];

int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i){
		scanf("%d%d",&x,&y);

		xx[i] = x;
		yy[i] = y;

		s[x].insert(y);
		s[y].insert(x);
	}
	srand(time(0));
	for(int op=1;op<=200;++op){
		for(i=1;i<=n;++i)p[i]=i;
		random_shuffle(p+1,p+n+1);
		p[n+1]=p[1];
		for(i=1;i<=m;++i) if(s[p[ xx[i] ]].count(p[ yy[i] ]))break;
		if(i==m+1){
			for(i=1;i<=m;++i)printf("%d %d\n",p[ xx[i] ],p[ yy[i] ] );
			return 0;
		}
	}
	printf("-1\n");
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<set>
#include<ctime>
#define N 120000
using namespace std;
int i,n,m,x,y,p[N];
set <int> s[N];

int xx[N] , yy[N];

int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i){
		scanf("%d%d",&x,&y);

		xx[i] = x;
		yy[i] = y;

		s[x].insert(y);
		s[y].insert(x);
	}
	srand(time(0));
	for(int op=1;op<=200;++op){
		for(i=1;i<=n;++i)p[i]=i;
		random_shuffle(p+1,p+n+1);
		p[n+1]=p[1];
		for(i=1;i<=m;++i) if(s[p[ xx[i] ]].count(p[ yy[i] ]))break;
		if(i==m+1){
			for(i=1;i<=m;++i)printf("%d %d\n",p[i],p[i+1]);
			return 0;
		}
	}
	printf("-1\n");
}


///==========================================================================
///
///                   Bismillah ir-Rahman ir-Rahim
///
/// ==========================================================================
///
///                    S.M.SHAHEEN SHA
///
///                    Dept. of Computer Science and Engineering
///                    Jahangirnagar University , Bangladesh
///
///                    Email : shaheen.cse20@gmail.com
///                    ID    : shaheen_bd
/// ==========================================================================

//#include<bits/stdc++.h>

#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<deque>
#include<climits>
#include<complex>

using namespace std;

#define LL long long
#define ULL unsigned long long

// I/O
#define I(X)                        scanf("%d",     &(X))
#define II(X, Y)                    scanf("%d%d",   &(X), &(Y))
#define III(X, Y, Z)                scanf("%d%d%d", &(X), &(Y), &(Z))

#define DI(X) int (X);              scanf("%d",     &X)
#define DII(X, Y) int X, Y;         scanf("%d%d",   &X, &Y)
#define DIII(X, Y, Z) int X, Y, Z;  scanf("%d%d%d", &X, &Y, &Z)

#define IL(x)                       scanf("%lld", &x)
#define IIL(x,y )                   scanf("%lld", &x,&y)
#define IIIL(x,y,z)                 scanf("%lld", &x,&y,&z)

#define DIL(x)       LL x;          scanf("%lld", &x)
#define DIIL(x,y)    LL x,y;        scanf("%lld", &x,&y)
#define DIIIL(x,y,z) LL x,y,z;      scanf("%lld", &x,&y,&z)

#define SS(s)                       scanf("%s",s)
#define S                           scanf
#define P                           printf

#define PI(x)                       printf("%d\n",      x)
#define PII(x,y)                    printf("%d %d\n",   x,y)
#define PIII(x,y,z)                 printf("%d %d %d\n",x,y,z)

#define PIL(x)                      printf("%lld\n",          x)
#define PIIL(x,y)                   printf("%lld %lld\n",     x,y)
#define PIIIL(x,y,z)                printf("%lld %lld %lld\n",x,y,z)

// LOOP
#define repv(i,a)  for(int i=0;i<(int)a.size();i++)
#define revv(i,a)  for(int i=((int)a.size())-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)

#define FS(x)      for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define PR(x)      for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) {  cout << *it << " "; } cout << endl;

// array initialization
#define MEM(a,val) memset(a,val,sizeof(a));
#define SET(a)     memset(a,-1,sizeof a)
#define CLR(a)     memset(a,0,sizeof a)

// min-max
#define Max(a,b)     (a>b?a:b)
#define _Max(a,b,c)  Max(a,Max(b,c))
#define Min(a,b)     (a<b?a:b)
#define _Min(a,b,c)  Min(a,Min(b,c))
#define MAX(a)       (*max_element(all(a)))
#define MIN(a)       (*min_element(all(a)))

#define SQR(n) (n*n)
#define eps    (1e-9)
#define pi     (2.0*acos(0.0)) //#define PI acos(-1.0)

#define all(a) a.begin(),a.end()
#define pb     push_back
#define NL     puts("");
// pair
#define X first
#define Y second

// binary search
#define LB(a,x) (lower_bound(all(a),x)-a.begin())
#define UB(a,x) (upper_bound(all(a),x)-a.begin())

// IO
#define READ  freopen("C:\\Users\\back_bencher\\Desktop\\input.txt","r",stdin)
#define WRITE freopen("C:\\Users\\back_bencher\\Desktop\\output.txt","w",stdout)
#define _cin  ios_base::sync_with_stdio(0); cin.tie(0);

#define pline cout << "_________________________" << endl;

// bit operation
#define countbit(x) __builtin_popcount(x)
template< class T, class X > inline bool checkbit(T a, X pos) { T t=1;return ((a&(t<<pos))>0);  }
template< class T, class X > inline T      setbit(T a, X pos) { T t=1;return (a|(t<<pos));      }
template< class T, class X > inline T    resetbit(T a, X pos) { T t=1;return (a&(~(t<<pos)));   }
template< class T, class X > inline T   togglebit(T a, X pos) { T t=1;return (a^(t<<pos));      }

// mathematics
template<typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T> T Bigmod(T base,T power,T mod) { T ret=1; while(power)  { if(power & 1) ret=(ret*base)%mod; base=(base*base)%mod;  power>>=1; }return ret; }
template<typename T> T ModInverse(T number,T mod) { return Bigmod(number,mod-2,mod); }
template<typename T> T GCD(T a,T b){if(a<0)return GCD(-a,b);if(b<0)return GCD(a,-b);return (b==0)?a:GCD(b,a%b);}
template<typename T> T LCM(T a,T b) {if(a<0)return LCM(-a,b);if(b<0)return LCM(a,-b);return a*(b/GCD(a,b));}
template<typename T> T EUCLIDE(T a,T b,T &x,T &y) {if(a<0){T d=euclide(-a,b,x,y);x=-x;return d;}   if(b<0){T d=euclide(a,-b,x,y);y=-y;return d;}   if(b==0){x=1;y=0;return a;}else{T d=euclide(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}
template<typename T> T ABS(T a) {if(a<0)return -a;else return a;}

// geometry
double DEG(double x) { return (180.0*x)/(pi);}
double RAD(double x) { return (x*(double)pi)/(180.0);}
template<typename T> T DIS(T x1,T y1,T x2, T y2){return sqrt( (double)( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) );}
template<typename T> T ANGLE(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
template<typename T> LL isLeft(T a,T b,T c) { return (c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y); }
// minmax
template<class T> inline bool setmin(T& a, T b) { return a>b? a=b, true: false; }
template<class T> inline bool setmax(T& a, T b) { return a<b? a=b, true: false; }
// debug
void P_ARR(int *ar,int a,int b) {  if(a>b) swap(a,b); if(a<=b) cout << ar[a]; for(int i=a+1;i<=b;i++) cout << " "<<ar[i];  cout << endl; }
template<typename T> T in(){ char ch; T n = 0; bool ng = false; while (1) { ch = getchar(); if (ch == '-') { ng = true; ch = getchar(); break;} if (ch>='0' && ch<='9') break; }    while (1) { n = n*10 + (ch - '0'); ch = getchar(); if (ch<'0' || ch>'9')   break;    }  return (ng?-n:n);  }
//
//#define VI  vector< int >
//#define VII vector< VI >
//#define VLL vector< LL >
//#define PII pair< int , int >
//#define PLL pair< LL , LL >
//#define VPI vector< PII >

//int month[]={31,28,31,30,31,30,31,31,30,31,30,31}; ///month
// dir[][0] = x value, dir[][1] = y value
//int dir[5][2] = { {0,0},{1,0},{0,1},{-1,0},{0,-1} }; /// 4 Direction
//int dir[9][2] = { {0,0},{1,0},{0,1},{-1,0},{0,-1},{-1,1},{-1,-1},{1,-1},{1,1}}; /// 8 direction
//int dir[9][2] = { {0,0},{2,1},{1,2},{-1,2},{-2,1},{-2,-1},{-1,-2},{1,-2},{2,-1} }///Knight Direction
//int dir[8][2] = { {0,0},{2,0},{1,1},{-1,1} ,{-2,0} , {-1,-1} ,{1,-1} };///Hexagonal Direction

/// ======================================================================================================

#define  debug  0
#define  DD     if(debug)

///             0123456789
#define  MX     1000007
#define  MOD    1000000007
#define  inf    1000000000

using namespace std;

set <int> s[MX];
int xx[MX] , yy[MX];

int main(){

    int x,y,p[MX];

	DII(n,m);

	rep(i,1,m)
    {
		II(x,y);

		s[x].insert(y);
		s[y].insert(x);
	}

	rep(i,1,n) p[i]=i;

	for(int op=1;op<=300;++op){

		random_shuffle(p+1,p+n+1);

		p[n+1]=p[1];

		int i;
        for(i=1; i<=m; ++i) if( s[p[ i ]].count(p[i+1] ) )break;

        if(i>m)
        {
            rep(j,1,m)  printf("%d %d\n",p[j],p[j+1]);
            return 0;
        }
	}

	printf("-1\n");
}


///==========================================================================
///
///                   Bismillah ir-Rahman ir-Rahim
///
/// ==========================================================================
///
///                    S.M.SHAHEEN SHA
///
///                    Dept. of Computer Science and Engineering
///                    Jahangirnagar University , Bangladesh
///
///                    Email : shaheen.cse20@gmail.com
///                    ID    : shaheen_bd
/// ==========================================================================

//#include<bits/stdc++.h>

#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<deque>
#include<climits>
#include<complex>

using namespace std;

#define LL long long
#define ULL unsigned long long

// I/O
#define I(X)                        scanf("%d",     &(X))
#define II(X, Y)                    scanf("%d%d",   &(X), &(Y))
#define III(X, Y, Z)                scanf("%d%d%d", &(X), &(Y), &(Z))

#define DI(X) int (X);              scanf("%d",     &X)
#define DII(X, Y) int X, Y;         scanf("%d%d",   &X, &Y)
#define DIII(X, Y, Z) int X, Y, Z;  scanf("%d%d%d", &X, &Y, &Z)

#define IL(x)                       scanf("%lld", &x)
#define IIL(x,y )                   scanf("%lld", &x,&y)
#define IIIL(x,y,z)                 scanf("%lld", &x,&y,&z)

#define DIL(x)       LL x;          scanf("%lld", &x)
#define DIIL(x,y)    LL x,y;        scanf("%lld", &x,&y)
#define DIIIL(x,y,z) LL x,y,z;      scanf("%lld", &x,&y,&z)

#define SS(s)                       scanf("%s",s)
#define S                           scanf
#define P                           printf

#define PI(x)                       printf("%d\n",      x)
#define PII(x,y)                    printf("%d %d\n",   x,y)
#define PIII(x,y,z)                 printf("%d %d %d\n",x,y,z)

#define PIL(x)                      printf("%lld\n",          x)
#define PIIL(x,y)                   printf("%lld %lld\n",     x,y)
#define PIIIL(x,y,z)                printf("%lld %lld %lld\n",x,y,z)

// LOOP
#define repv(i,a)  for(int i=0;i<(int)a.size();i++)
#define revv(i,a)  for(int i=((int)a.size())-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)

#define FS(x)      for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define PR(x)      for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) {  cout << *it << " "; } cout << endl;

// array initialization
#define MEM(a,val) memset(a,val,sizeof(a));
#define SET(a)     memset(a,-1,sizeof a)
#define CLR(a)     memset(a,0,sizeof a)

// min-max
#define Max(a,b)     (a>b?a:b)
#define _Max(a,b,c)  Max(a,Max(b,c))
#define Min(a,b)     (a<b?a:b)
#define _Min(a,b,c)  Min(a,Min(b,c))
#define MAX(a)       (*max_element(all(a)))
#define MIN(a)       (*min_element(all(a)))

#define SQR(n) (n*n)
#define eps    (1e-9)
#define pi     (2.0*acos(0.0)) //#define PI acos(-1.0)

#define all(a) a.begin(),a.end()
#define pb     push_back
#define NL     puts("");
// pair
#define X first
#define Y second

// binary search
#define LB(a,x) (lower_bound(all(a),x)-a.begin())
#define UB(a,x) (upper_bound(all(a),x)-a.begin())

// IO
#define READ  freopen("C:\\Users\\back_bencher\\Desktop\\input.txt","r",stdin)
#define WRITE freopen("C:\\Users\\back_bencher\\Desktop\\output.txt","w",stdout)
#define _cin  ios_base::sync_with_stdio(0); cin.tie(0);

#define pline cout << "_________________________" << endl;

// bit operation
#define countbit(x) __builtin_popcount(x)
template< class T, class X > inline bool checkbit(T a, X pos) { T t=1;return ((a&(t<<pos))>0);  }
template< class T, class X > inline T      setbit(T a, X pos) { T t=1;return (a|(t<<pos));      }
template< class T, class X > inline T    resetbit(T a, X pos) { T t=1;return (a&(~(t<<pos)));   }
template< class T, class X > inline T   togglebit(T a, X pos) { T t=1;return (a^(t<<pos));      }

// mathematics
template<typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T> T Bigmod(T base,T power,T mod) { T ret=1; while(power)  { if(power & 1) ret=(ret*base)%mod; base=(base*base)%mod;  power>>=1; }return ret; }
template<typename T> T ModInverse(T number,T mod) { return Bigmod(number,mod-2,mod); }
template<typename T> T GCD(T a,T b){if(a<0)return GCD(-a,b);if(b<0)return GCD(a,-b);return (b==0)?a:GCD(b,a%b);}
template<typename T> T LCM(T a,T b) {if(a<0)return LCM(-a,b);if(b<0)return LCM(a,-b);return a*(b/GCD(a,b));}
template<typename T> T EUCLIDE(T a,T b,T &x,T &y) {if(a<0){T d=euclide(-a,b,x,y);x=-x;return d;}   if(b<0){T d=euclide(a,-b,x,y);y=-y;return d;}   if(b==0){x=1;y=0;return a;}else{T d=euclide(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}
template<typename T> T ABS(T a) {if(a<0)return -a;else return a;}

// geometry
double DEG(double x) { return (180.0*x)/(pi);}
double RAD(double x) { return (x*(double)pi)/(180.0);}
template<typename T> T DIS(T x1,T y1,T x2, T y2){return sqrt( (double)( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) );}
template<typename T> T ANGLE(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
template<typename T> LL isLeft(T a,T b,T c) { return (c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y); }
// minmax
template<class T> inline bool setmin(T& a, T b) { return a>b? a=b, true: false; }
template<class T> inline bool setmax(T& a, T b) { return a<b? a=b, true: false; }
// debug
void P_ARR(int *ar,int a,int b) {  if(a>b) swap(a,b); if(a<=b) cout << ar[a]; for(int i=a+1;i<=b;i++) cout << " "<<ar[i];  cout << endl; }
template<typename T> T in(){ char ch; T n = 0; bool ng = false; while (1) { ch = getchar(); if (ch == '-') { ng = true; ch = getchar(); break;} if (ch>='0' && ch<='9') break; }    while (1) { n = n*10 + (ch - '0'); ch = getchar(); if (ch<'0' || ch>'9')   break;    }  return (ng?-n:n);  }
//
//#define VI  vector< int >
//#define VII vector< VI >
//#define VLL vector< LL >
//#define PII pair< int , int >
//#define PLL pair< LL , LL >
//#define VPI vector< PII >

//int month[]={31,28,31,30,31,30,31,31,30,31,30,31}; ///month
// dir[][0] = x value, dir[][1] = y value
//int dir[5][2] = { {0,0},{1,0},{0,1},{-1,0},{0,-1} }; /// 4 Direction
//int dir[9][2] = { {0,0},{1,0},{0,1},{-1,0},{0,-1},{-1,1},{-1,-1},{1,-1},{1,1}}; /// 8 direction
//int dir[9][2] = { {0,0},{2,1},{1,2},{-1,2},{-2,1},{-2,-1},{-1,-2},{1,-2},{2,-1} }///Knight Direction
//int dir[8][2] = { {0,0},{2,0},{1,1},{-1,1} ,{-2,0} , {-1,-1} ,{1,-1} };///Hexagonal Direction

/// ======================================================================================================

#define  debug  0
#define  DD     if(debug)

///             0123456789
#define  MX     1000007
#define  MOD    1000000007
#define  inf    1000000000

using namespace std;

set <int> s[MX];
int xx[MX] , yy[MX];

int main(){

    int x,y,p[MX];

	DII(n,m);

	rep(i,1,m)
    {
		II(x,y);

		s[x].insert(y);
		s[y].insert(x);
	}

	rep(i,1,n) p[i]=i;

	for(int op=1;op<=300;++op){

		random_shuffle(p+1,p+n+1);

		p[n+1]=p[1];

		int i;
        for(i=1; i<=m; i++)  if( s[p[ i ]].count(p[i+1] ) ) break;

        if(i>m)
        {
            rep(j,1,m)  printf("%d %d\n",p[j],p[j+1]);
            return 0;
        }
	}

	printf("-1\n");
}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <queue>
using namespace std;

vector<int> link1[100100];

int nxt[100100];

int e[100100],N,M;

bool judge(int aa,int bb)
{
    for(int i=0;i<link1[aa].size();i++) if(link1[aa][i]==bb) return false;
    if(e[aa]==bb||e[bb]==aa||aa==bb) return false;
    return true;
}

bool dfs(int x,int num)
{
    if(num==M) return true;
    if(e[x]!=-1) return false;
    int pre=0;
    for(int i=nxt[0];i<=N;i=nxt[i])
    {
        if(judge(x,i))
        {
            e[x]=i;
            nxt[pre]=nxt[i];
            if(dfs(i,num+1)) return true;
            nxt[pre]=i;
        }

        pre=i;
    }
    return false;
}

int main()
{
    int x,y;
    while(scanf("%d%d",&N,&M)!=EOF)
    {
        for(int i=1;i<=N;i++) link1[i].clear();
        for(int i=0;i<M;i++)
        {
            scanf("%d%d",&x,&y);
            link1[x].push_back(y);
            link1[y].push_back(x);
        }
        memset(e,-1,sizeof(e));

        for(int i=1;i<=N;i++)
        {
            nxt[i]=i+1;
        }
        nxt[0]=1;

        if(N>=9)
        {
            if(dfs(1,0))
            {
                for(int i=1;i<=N;i++)
                {
                    if(e[i]!=-1) printf("%d %d\n",i,e[i]);
                }
            }
            else printf("-1\n");
        }
        else
        {
            bool flag=0;
            for(int i=1;i<=N;i++)
            {
                memset(e,-1,sizeof(e));
                for(int i=1;i<=N;i++)
                {
                    nxt[i]=i+1;
                }
                nxt[0]=1;
                if(dfs(i,0))
                {
                    flag=true;
                    for(int i=1;i<=N;i++)
                    {
                        if(e[i]!=-1) printf("%d %d\n",i,e[i]);
                    }
                    break;
                }

            }
            if(!flag) printf("-1\n");
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <queue>
using namespace std;

vector<int> link1[100100];

int nxt[100100];

int e[100100],N,M;

bool judge(int aa,int bb)
{
    for(int i=0;i<link1[aa].size();i++) if(link1[aa][i]==bb) return false;
    if(e[aa]==bb||e[bb]==aa||aa==bb) return false;
    return true;
}

bool dfs(int x,int num)
{
    if(num==M) return true;
    if(e[x]!=-1) return false;
    int pre=0;
    for(int i=nxt[0];i<=N;i=nxt[i])
    {
        if(judge(x,i))
        {
            e[x]=i;
            nxt[pre]=nxt[i];
            if(dfs(i,num+1)) return true;
            nxt[pre]=i;
        }

        pre=i;
    }
    return false;
}

int main()
{
    int x,y;
    while(scanf("%d%d",&N,&M)!=EOF)
    {
        for(int i=1;i<=N;i++) link1[i].clear();
        for(int i=0;i<M;i++)
        {
            scanf("%d%d",&x,&y);
            link1[x].push_back(y);
            link1[y].push_back(x);
        }
        memset(e,-1,sizeof(e));

        for(int i=1;i<=N;i++)
        {
            nxt[i]=i+1;
        }
        nxt[0]=1;

        if(dfs(1,0))
        {
            for(int i=1;i<=N;i++)
            {
                if(e[i]!=-1) printf("%d %d\n",i,e[i]);
            }
        }
        else printf("-1\n");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <queue>
using namespace std;

vector<int> link1[100100];

int nxt[100100];

int e[100100],N,M;

bool judge(int aa,int bb)
{
    for(int i=0;i<link1[aa].size();i++) if(link1[aa][i]==bb) return false;
    if(e[aa]==bb||e[bb]==aa||aa==bb) return false;
    return true;
}

bool dfs(int x,int num)
{
    if(num==M) return true;
    if(e[x]!=-1) return false;
    int pre=0;
    for(int i=nxt[0];i<=N;i=nxt[i])
    {
        if(judge(x,i))
        {
            e[x]=i;
            nxt[pre]=nxt[i];
            if(dfs(i,num+1)) return true;
            nxt[pre]=i;
        }

        pre=i;
    }
    return false;
}

int main()
{
    int x,y;
    while(scanf("%d%d",&N,&M)!=EOF)
    {
        for(int i=1;i<=N;i++) link1[i].clear();
        for(int i=0;i<M;i++)
        {
            scanf("%d%d",&x,&y);
            link1[x].push_back(y);
            link1[y].push_back(x);
        }
        memset(e,-1,sizeof(e));

        for(int i=1;i<=N;i++)
        {
            nxt[i]=i+1;
        }
        nxt[0]=1;

        if(N>=6)
        {
            if(dfs(1,0))
            {
                for(int i=1;i<=N;i++)
                {
                    if(e[i]!=-1) printf("%d %d\n",i,e[i]);
                }
            }
            else printf("-1\n");
        }
        else
        {
            bool flag=0;
            for(int i=1;i<=N;i++)
            {
                memset(e,-1,sizeof(e));
                for(int i=1;i<=N;i++)
                {
                    nxt[i]=i+1;
                }
                nxt[0]=1;
                if(dfs(i,0))
                {
                    flag=true;
                    for(int i=1;i<=N;i++)
                    {
                        if(e[i]!=-1) printf("%d %d\n",i,e[i]);
                    }
                    break;
                }

            }
            if(!flag) printf("-1\n");
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <queue>
using namespace std;

vector<int> link1[100100];

int nxt[100100];

int e[100100],N,M;

bool judge(int aa,int bb)
{
    for(int i=0;i<link1[aa].size();i++) if(link1[aa][i]==bb) return false;
    if(e[aa]==bb||e[bb]==aa||aa==bb) return false;
    return true;
}

bool dfs(int x,int num)
{
    if(num==M) return true;
    if(e[x]!=-1) return false;
    int pre=0;
    for(int i=nxt[0];i<=N;i=nxt[i])
    {
        if(judge(x,i))
        {
            e[x]=i;
            nxt[pre]=nxt[i];
            if(dfs(i,num+1)) return true;
            nxt[pre]=i;
            e[x]=-1;
        }

        pre=i;
    }
    return false;
}

int main()
{
    //freopen("in.txt","r",stdin);
    int x,y;
    while(scanf("%d%d",&N,&M)!=EOF)
    {
        for(int i=1;i<=N;i++) link1[i].clear();
        for(int i=0;i<M;i++)
        {
            scanf("%d%d",&x,&y);
            link1[x].push_back(y);
            link1[y].push_back(x);
        }
        memset(e,-1,sizeof(e));

        for(int i=1;i<=N;i++)
        {
            nxt[i]=i+1;
        }
        nxt[0]=1;

        if(N>=9)
        {
            if(dfs(1,0))
            {
                for(int i=1;i<=N;i++)
                {
                    if(e[i]!=-1) printf("%d %d\n",i,e[i]);
                }
            }
            else printf("-1\n");
/*
            for(int i=1;i<=N;i++)
            {
                cout<<i<<" "<<e[i]<<" "<<nxt[i]<<endl;
            }
*/
        }
        else
        {
            bool flag=0;
            for(int i=1;i<=N;i++)
            {
                memset(e,-1,sizeof(e));
                for(int i=1;i<=N;i++)
                {
                    nxt[i]=i+1;
                }
                nxt[0]=1;
                if(dfs(i,0))
                {
                    flag=true;
                    for(int i=1;i<=N;i++)
                    {
                        if(e[i]!=-1) printf("%d %d\n",i,e[i]);
                    }
                    break;
                }

            }

            if(!flag) printf("-1\n");
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <queue>
using namespace std;

vector<int> link1[100100];

int nxt[100100];

int e[100100],N,M;

bool judge(int aa,int bb)
{
    for(int i=0;i<link1[aa].size();i++) if(link1[aa][i]==bb) return false;
    if(e[aa]==bb||e[bb]==aa) return false;
    return true;
}

bool dfs(int x,int num)
{
    if(num==M) return true;
    if(e[x]!=-1) return false;
    int pre=0;
    for(int i=nxt[0];i<=N;i=nxt[i])
    {
        if(judge(x,i))
        {
            e[x]=i;
            nxt[pre]=nxt[i];
            if(dfs(i,num+1)) return true;
            nxt[pre]=i;
        }

        pre=i;
    }
    return false;
}

int main()
{
    int x,y;
    while(scanf("%d%d",&N,&M)!=EOF)
    {
        for(int i=1;i<=N;i++) link1[i].clear();
        for(int i=0;i<M;i++)
        {
            scanf("%d%d",&x,&y);
            link1[x].push_back(y);
            link1[y].push_back(x);
        }
        memset(e,-1,sizeof(e));

        for(int i=1;i<=N;i++)
        {
            nxt[i]=i+1;
        }
        nxt[0]=1;

        if(dfs(1,0))
        {
            for(int i=1;i<=N;i++)
            {
                if(e[i]!=-1) printf("%d %d\n",i,e[i]);
            }
        }
        else printf("-1\n");
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
/////valori pentru solutie
int n, m, muc[100009][2], v[100009];

void add_vec (int x, int y)
{
    muc [ x ] [++ muc [ x ] [ 0 ] ] = y;
}

bool muchie (int x, int y)
{
    if (x>y) return muchie (y, x);
    for (int i=0; i<=muc[x][0]; i++)
        if (muc[x][i] == y) return 1;
    return 0;
}

/////valori pentru back
int nr, x[20], y[20], ap[20], fin;

void back (int poz)
{
    if (fin) return ;
    if (poz == nr + 1)
    {
        int deg[10], nm=0;
        for (int i=1; i<=n; i++)
            deg[i] = 0;
        for (int i=1; i<=nr; i++)
            if (ap[i] == 1)
            {
                deg[x[i]]++;
                deg[y[i]]++;
                nm++;
            }
        if (nm != m) return;
        for (int i=1; i<=n; i++)
            if (deg[i]>2) return ;
        fin = 1;
        for (int i=1; i<=nr; i++)
            if (ap[i]) printf ("%d %d\n", x[i], y[i]);
        return;
    }
    back (poz+1);
    ap[poz] = 1;
    back (poz+1);
    ap[poz] = 0;
}

int main()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
scanf ("%d", &n);
scanf ("%d", &m);
if (n<=6)
{
    bool ap[30][30];
    for (int i=1; i<=n; i++)
        for (int j=1; j<=n; j++)
            ap[i][j] = 0;

    for (int i=1; i<=m; i++)
    {
        int x, y;
        scanf ("%d%d", &x, &y);
        ap[x][y]=ap[y][x]=1;
    }

    for (int i=1; i<=n; i++)
        for (int j=i+1; j<=n; j++)
            if (ap[i][j] == 0)
            {
                nr++;
                x[nr] = i;
                y[nr] = j;
            }

    fin = 0;
    back (1);
    if (fin == 0) printf ("-1\n");
    return 0;
}

for (int i=1; i<=m; i++)
{
    int x, y;
    scanf ("%d %d", &x, &y);
    if (x<y) add_vec(x, y);
    else add_vec(y, x);
}

for (int i=1; i<=n; i++)
    v[i] = i;
v[n+1] = 1;

for (int i=1; i<=n; i++)
    if (muchie (v[i], v[i+1]))
    {
        int j;
        for (j=i+2; j<=n; j++)
            if (muchie (v[i], v[j]) == 0) break;
        if (j<=n)
        {
            reverse (v+i+1, v+j+1);
            continue;
        }
        for (int j=i-1; j>1; j--)
            if (muchie (v[i+1], v[j]) == 0 && muchie (v[i], v[j-1]) == 0) break;
        reverse (v+j, v+i+1);
    }

for (int i=1; i<=m; i++)
    printf ("%d %d\n", v[i], v[i+1]);
return 0;
}


#include<cstdio>
#include<vector>
#include<cstdlib>
#include<ctime>
using namespace std;
int n, nr;
char A[5009][5009];
vector < int > v[2];
int main()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
srand(time(0));
scanf ("%d\n", &n);
for (int i=1; i<=n; i++)
    gets(A[i]+1);
if (n<=2)
{
    printf("-1\n");
    return 0;
}
while (1)
{
    int i = rand()%(n-2) + 1;
    v[0].clear();
    v[1].clear();
    for (int j=i+1; j<=n; j++)
        if (j!=i) v[A[i][j] - '0'] . push_back(j);
    for (vector < int > :: iterator I = v[0].begin(); I!=v[0].end(); I++)
        for (vector < int > :: iterator J = v[1].begin(); J!=v[1].end(); J++)
            if (A[*J][*I]=='1')
            {
                printf ("%d %d %d\n", i, *J, *I);
                return 0;
            }
    nr ++;
    if (nr>29)
    {
        printf ("-1\n");
        return 0;
    }
}
printf ("-1\n");
return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
/////valori pentru solutie
int n, m, muc[100009][3], v[100009];

void add_vec (int x, int y)
{
    muc [ x ] [++ muc [ x ] [ 0 ] ] = y;
}

bool muchie (int x, int y)
{
    if (x>y) return muchie (y, x);
    for (int i=0; i<=muc[x][0]; i++)
        if (muc[x][i] == y) return 1;
    return 0;
}

/////valori pentru back
int nr, x[20], y[20], ap[20], fin;

void back (int poz)
{
    if (fin) return ;
    if (poz == nr + 1)
    {
        int deg[10], nm=0;
        for (int i=1; i<=n; i++)
            deg[i] = 0;
        for (int i=1; i<=nr; i++)
            if (ap[i] == 1)
            {
                deg[x[i]]++;
                deg[y[i]]++;
                nm++;
            }
        if (nm != m) return;
        for (int i=1; i<=n; i++)
            if (deg[i]>2) return ;
        fin = 1;
        for (int i=1; i<=nr; i++)
            if (ap[i]) printf ("%d %d\n", x[i], y[i]);
        return;
    }
    back (poz+1);
    ap[poz] = 1;
    back (poz+1);
    ap[poz] = 0;
}

int main()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
scanf ("%d", &n);
scanf ("%d", &m);
if (n<=6)
{
    bool ap[30][30];
    for (int i=1; i<=n; i++)
        for (int j=1; j<=n; j++)
            ap[i][j] = 0;

    for (int i=1; i<=m; i++)
    {
        int x, y;
        scanf ("%d%d", &x, &y);
        ap[x][y]=ap[y][x]=1;
    }

    for (int i=1; i<=n; i++)
        for (int j=i+1; j<=n; j++)
            if (ap[i][j] == 0)
            {
                nr++;
                x[nr] = i;
                y[nr] = j;
            }

    fin = 0;
    back (1);
    if (fin == 0) printf ("-1\n");
    return 0;
}

for (int i=1; i<=m; i++)
{
    int x, y;
    scanf ("%d %d", &x, &y);
    if (x<y) add_vec(x, y);
    else add_vec(y, x);
}

for (int i=1; i<=n; i++)
    v[i] = i;
v[n+1] = 1;

for (int i=1; i<=n; i++)
    if (muchie (v[i], v[i+1]))
    {
        int j;
        for (j=i+2; j<=n; j++)
            if (muchie (v[i], v[j]) == 0) break;
        if (j<=n)
        {
            reverse (v+i+1, v+j+1);
            continue;
        }
        for (j=i-1; j>1; j--)
            if (muchie (v[i+1], v[j]) == 0 && muchie (v[i], v[j-1]) == 0) break;
        reverse (v+j, v+i+1);
    }

for (int i=1; i<=m; i++)
    printf ("%d %d\n", v[i], v[i+1]);
return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
/////valori pentru solutie
int n, m, muc[100009][2], v[100009];

void add_vec (int x, int y)
{
    muc [ x ] [++ muc [ x ] [ 0 ] ] = y;
}

bool muchie (int x, int y)
{
    if (x>y) return muchie (y, x);
    for (int i=0; i<=muc[x][0]; i++)
        if (muc[x][i] == y) return 1;
    return 0;
}

/////valori pentru back
int nr, x[20], y[20], ap[20], fin;

void back (int poz)
{
    if (fin) return ;
    if (poz == nr + 1)
    {
        int deg[10], nm=0;
        for (int i=1; i<=n; i++)
            deg[i] = 0;
        for (int i=1; i<=nr; i++)
            if (ap[i] == 1)
            {
                deg[x[i]]++;
                deg[y[i]]++;
                nm++;
            }
        if (nm != m) return;
        for (int i=1; i<=n; i++)
            if (deg[i]>2) return ;
        fin = 1;
        for (int i=1; i<=nr; i++)
            if (ap[i]) printf ("%d %d\n", x[i], y[i]);
        return;
    }
    back (poz+1);
    ap[poz] = 1;
    back (poz+1);
    ap[poz] = 0;
}

int main()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
scanf ("%d", &n);
scanf ("%d", &m);
if (n<=6)
{
    bool ap[30][30];
    for (int i=1; i<=n; i++)
        for (int j=1; j<=n; j++)
            ap[i][j] = 0;

    for (int i=1; i<=m; i++)
    {
        int x, y;
        scanf ("%d%d", &x, &y);
        ap[x][y]=ap[y][x]=1;
    }

    for (int i=1; i<=n; i++)
        for (int j=i+1; j<=n; j++)
            if (ap[i][j] == 0)
            {
                nr++;
                x[nr] = i;
                y[nr] = j;
            }

    fin = 0;
    back (1);
    if (fin == 0) printf ("-1\n");
    return 0;
}

for (int i=1; i<=m; i++)
{
    int x, y;
    scanf ("%d %d", &x, &y);
    if (x<y) add_vec(x, y);
    else add_vec(y, x);
}

for (int i=1; i<=n; i++)
    v[i] = i;
v[n+1] = 1;

for (int i=1; i<=n; i++)
    if (muchie (v[i], v[i+1]))
    {
        int j;
        for (j=i+2; j<=n; j++)
            if (muchie (v[i], v[j]) == 0) break;
        if (j<=n)
        {
            reverse (v+i+1, v+j+1);
            continue;
        }
        for (j=i-1; j>1; j--)
            if (muchie (v[i+1], v[j]) == 0 && muchie (v[i], v[j-1]) == 0) break;
        reverse (v+j, v+i+1);
    }

for (int i=1; i<=m; i++)
    printf ("%d %d\n", v[i], v[i+1]);
return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<assert.h>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9
#define asdf exit(0);

typedef long long LL;

vector<int> adj[100010];
map< pair<int,int>,int > mp;

int vis[100010];

vector<int> order1,order;
vector<int> ans;

void merge()
{
    int i;
    for(i=0;i<order1.size();i++)
        order.push_back(order1[i]);
}

void dfs(int u)
{
    int i,v;
    vis[u]=1;
    order1.push_back(u);
    for(i=0; i<adj[u].size(); i++)
    {
        v=adj[u][i];
        if(vis[v]) continue;
        dfs(v);
    }
}

vector<int> tree[3];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int n,m,x,y,i,j,j1,j2;
    scanf("%d %d",&n,&m);

    for(i=0; i<m; i++)
    {
        scanf("%d %d",&x,&y);
        x--;
        y--;
        mp[make_pair(x,y)]=1;
        mp[make_pair(y,x)]=1;

        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    if(n<=5)
    {
        vector< pair<int,int> > vp;
        for(i=0; i<n; i++)
            for(j=i+1; j<n; j++)
            {
                vp.push_back(make_pair(i,j));
            }

        int grid[6][6];
        int N=vp.size();

        for(i=0; i<(1<<N); i++)
        {
            if(__builtin_popcount(i)==m)
            {
                memset(grid,0,sizeof(grid));
                for(j=0; j<N; j++)
                {
                    if(i & (1<<j))
                    {
                        grid[vp[j].first][vp[j].second]=1;
                        grid[vp[j].second][vp[j].first]=1;
                        if(mp.find( vp[j]  )!=mp.end()) break;
                    }
                }
                if(j!=N) continue;

                int cnt=1;
                for(j1=0; j1<n; j1++)
                {
                    int cn=0;
                    for(j2=0; j2<n; j2++)
                    {
                        cn+=grid[j1][j2];
                    }
                    if(cn>2) cnt=0;
                }
                if(cnt==0) continue;

                for(i=0;i<n;i++)
                for(j=i+1;j<n;j++)
                {
                    if(grid[i][j]) printf("%d %d\n",i+1,j+1);
                }
                return 0;

            }

        }
        printf("-1\n");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        if(vis[i]==0)
        {
            dfs(i);
            if(order1.size()!=3)
            {
                merge();
            }
            else
            {
                tree[0].push_back(order1[0]);
                tree[1].push_back(order1[1]);
                tree[2].push_back(order1[2]);
            }
            order1.clear();
        }
    }

    if(tree[0].size()!=1)
    {
        for(i=0;i<tree[0].size();i++)
        {
            ans.push_back(tree[0][i]);
            ans.push_back(tree[1][i]);
            ans.push_back(tree[2][i]);
        }
        tree[0].clear();
        tree[1].clear();
        tree[2].clear();
    }

    if(ans.size())
    {
        int x1=ans.back();ans.pop_back();
        int x2=ans.back();ans.pop_back();

        for(i=0;i<order.size();i+=2) ans.push_back(order[i]);
        ans.push_back(x1);

        for(i=1;i<order.size();i+=2) ans.push_back(order[i]);
        ans.push_back(x2);
    }
    else
    {
        memset(vis,0,sizeof(vis));
        for(i=0; i<order.size(); i+=2)
        {
            ans.push_back( order[i] );
            vis[i]=1;
        }

        for(i=1; i<order.size(); i+=2)
        {
            ans.push_back( order[i] );
            vis[i]=1;
            break;
        }

        for(i=((int)order.size())-1; i>=0; i--)
        {
            if(vis[i]==0) ans.push_back(order[i]);
        }

        if(tree[0].size()!=0)
        {
            int x1=ans.back();ans.pop_back();
            int x2=ans.back();ans.pop_back();

            ans.push_back(tree[0][0]);
            ans.push_back(x1);
            ans.push_back(tree[1][0]);
            ans.push_back(x2);
            ans.push_back(tree[2][0]);
        }
    }

    for(i=0; i<m; i++)
    {
        printf("%d %d\n",ans[i]+1,ans[(i+1)%ans.size()]+1);
    }

    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<assert.h>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9
#define asdf exit(0);

typedef long long LL;

vector<int> adj[100010];
map< pair<int,int>,int > mp;

int vis[100010];
int home[100010];

vector<int> ans;
vector<int> tree[3];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int n,m,x,y,i,j,j1,j2;
    scanf("%d %d",&n,&m);

    for(i=0; i<m; i++)
    {
        scanf("%d %d",&x,&y);
        x--;
        y--;
        mp[make_pair(x,y)]=1;
        mp[make_pair(y,x)]=1;

        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    if(n<=5)
    {
        vector< pair<int,int> > vp;
        for(i=0; i<n; i++)
            for(j=i+1; j<n; j++)
            {
                vp.push_back(make_pair(i,j));
            }

        int grid[6][6];
        int N=vp.size();

        for(i=0; i<(1<<N); i++)
        {
            if(__builtin_popcount(i)==m)
            {
                memset(grid,0,sizeof(grid));
                for(j=0; j<N; j++)
                {
                    if(i & (1<<j))
                    {
                        grid[vp[j].first][vp[j].second]=1;
                        grid[vp[j].second][vp[j].first]=1;
                        if(mp.find( vp[j]  )!=mp.end()) break;
                    }
                }
                if(j!=N) continue;

                int cnt=1;
                for(j1=0; j1<n; j1++)
                {
                    int cn=0;
                    for(j2=0; j2<n; j2++)
                    {
                        cn+=grid[j1][j2];
                    }
                    if(cn>2) cnt=0;
                }
                if(cnt==0) continue;

                for(i=0;i<n;i++)
                for(j=i+1;j<n;j++)
                {
                    if(grid[i][j]) printf("%d %d\n",i+1,j+1);
                }
                return 0;

            }

        }
        printf("-1\n");
        return 0;
    }

    vector<int> v;
    for(i=0;i<6;i++) v.push_back(i);

    for(i=0;i<725;i++)
    {

        for(j=0;j<6;j++)
        {
            x=v[j];
            y=v[(j+1)%6];

            if(mp.find(make_pair(x,y))!=mp.end()) break;
        }
        if(j==6) break;
        next_permutation(v.begin(),v.end());
    }

   // cout<<i;
   // asdf

    for(i=0;i<3;i++)
    {
        tree[i].push_back(v[2*i]);
        tree[i].push_back(v[2*i+1]);

    }

    for(i=6;i<n;i++)
    {
        for(j=0;j<3;j++)
        {
            x=tree[(j+1)%3][0];
            y=tree[j][ tree[j].size()-1 ];

            if(mp.find(make_pair(x,i))==mp.end() && mp.find(make_pair(y,i))==mp.end())
            {
                tree[j].push_back(i);
                break;
            }
        }
    }

    for(i=0;i<3;i++)
    {
        for(j=0;j<tree[i].size();j++)
        {
            ans.push_back(tree[i][j]);
        }
    }

    for(i=0; i<m; i++)
    {
        printf("%d %d\n",ans[i]+1,ans[(i+1)%ans.size()]+1);
    }

    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<assert.h>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9
#define asdf exit(0);

typedef long long LL;

vector<int> adj[100010];
map< pair<int,int>,int > mp;

int vis[100010];

vector<int> order1,order;
vector<int> ans;

void merge()
{
    int i;
    for(i=0;i<order1.size();i++)
        order.push_back(order1[i]);
}

void dfs(int u)
{
    int i,v;
    vis[u]=1;
    order1.push_back(u);
    for(i=0; i<adj[u].size(); i++)
    {
        v=adj[u][i];
        if(vis[v]) continue;
        dfs(v);
    }
}

vector<int> tree[3];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int n,m,x,y,i,j,j1,j2;
    scanf("%d %d",&n,&m);

    for(i=0; i<m; i++)
    {
        scanf("%d %d",&x,&y);
        x--;
        y--;
        mp[make_pair(x,y)]=1;
        mp[make_pair(y,x)]=1;

        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    if(n<=5)
    {
        vector< pair<int,int> > vp;
        for(i=0; i<n; i++)
            for(j=i+1; j<n; j++)
            {
                vp.push_back(make_pair(i,j));
            }

        int grid[6][6];
        int N=vp.size();

        for(i=0; i<(1<<N); i++)
        {
            if(__builtin_popcount(i)==m)
            {
                memset(grid,0,sizeof(grid));
                for(j=0; j<N; j++)
                {
                    if(i & (1<<j))
                    {
                        grid[vp[j].first][vp[j].second]=1;
                        grid[vp[j].second][vp[j].first]=1;
                        if(mp.find( vp[j]  )!=mp.end()) break;
                    }
                }
                if(j!=N) continue;

                int cnt=1;
                for(j1=0; j1<n; j1++)
                {
                    int cn=0;
                    for(j2=0; j2<n; j2++)
                    {
                        cn+=grid[j1][j2];
                    }
                    if(cn>2) cnt=0;
                }
                if(cnt==0) continue;

                for(i=0;i<n;i++)
                for(j=i+1;j<n;j++)
                {
                    if(grid[i][j]) printf("%d %d\n",i+1,j+1);
                }
                return 0;

            }

        }
        printf("-1\n");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        if(vis[i]==0 && (adj[i].size()==0 || adj[i].size()==1) )
        {
            dfs(i);
         //   cout<<i+1<<" "<<order1.size()<<endl;
            if(order1.size()!=3)
            {
                merge();
            }
            else
            {
                tree[0].push_back(order1[0]);
                tree[1].push_back(order1[1]);
                tree[2].push_back(order1[2]);
            }
            order1.clear();
        }
    }

   // asdf

    for(i=0; i<n; i++)
    {
        if(vis[i]==0 )
        {
            dfs(i);
            if(order1.size()!=3)
            {
                merge();
            }
            else
            {
                tree[0].push_back(order1[0]);
                tree[1].push_back(order1[1]);
                tree[2].push_back(order1[2]);
            }
            order1.clear();
        }
    }

    if(tree[0].size()!=1)
    {
        for(j=0;j<3;j++)
        for(i=0;i<tree[j].size();i++)
        {
            ans.push_back(tree[j][i]);
            //cout<<tree[j][i]+1<<" ";
        }
       // asdf

        tree[0].clear();
        tree[1].clear();
        tree[2].clear();
    }

    //asdf

    if(ans.size())
    {
        int x1=ans.back();ans.pop_back();
        int x2=ans.back();ans.pop_back();

        for(i=0;i<order.size();i+=2) ans.push_back(order[i]);
        ans.push_back(x2);

        for(i=1;i<order.size();i+=2) ans.push_back(order[i]);
        ans.push_back(x1);
    }
    else
    {
        memset(vis,0,sizeof(vis));
        for(i=0; i<order.size(); i+=2)
        {
            ans.push_back( order[i] );
            vis[i]=1;
        }

        for(i=1; i<order.size(); i+=2)
        {
            ans.push_back( order[i] );
            vis[i]=1;
            break;
        }

        for(i=((int)order.size())-1; i>=0; i--)
        {
            if(vis[i]==0) ans.push_back(order[i]);
        }

        if(tree[0].size()!=0)
        {
            int x1=ans.back();ans.pop_back();
            int x2=ans.back();ans.pop_back();

            ans.push_back(tree[0][0]);
            ans.push_back(x1);
            ans.push_back(tree[1][0]);
            ans.push_back(x2);
            ans.push_back(tree[2][0]);
        }
    }

    for(i=0; i<m; i++)
    {
        printf("%d %d\n",ans[i]+1,ans[(i+1)%ans.size()]+1);
    }

    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<assert.h>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9
#define asdf exit(0);

typedef long long LL;

vector<int> adj[100010];
map< pair<int,int>,int > mp;

int vis[100010];

vector<int> order1,order;
vector<int> ans;

void merge()
{
    int i;
    for(i=0;i<order1.size();i++)
        order.push_back(order1[i]);
}

void dfs(int u)
{
    int i,v;
    vis[u]=1;
    order1.push_back(u);
    for(i=0; i<adj[u].size(); i++)
    {
        v=adj[u][i];
        if(vis[v]) continue;
        dfs(v);
    }
}

vector<int> tree[3];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int n,m,x,y,i,j,j1,j2;
    scanf("%d %d",&n,&m);

    for(i=0; i<m; i++)
    {
        scanf("%d %d",&x,&y);
        x--;
        y--;
        mp[make_pair(x,y)]=1;
        mp[make_pair(y,x)]=1;

        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    if(n<=5)
    {
        vector< pair<int,int> > vp;
        for(i=0; i<n; i++)
            for(j=i+1; j<n; j++)
            {
                vp.push_back(make_pair(i,j));
            }

        int grid[6][6];
        int N=vp.size();

        for(i=0; i<(1<<N); i++)
        {
            if(__builtin_popcount(i)==m)
            {
                memset(grid,0,sizeof(grid));
                for(j=0; j<N; j++)
                {
                    if(i & (1<<j))
                    {
                        grid[vp[j].first][vp[j].second]=1;
                        grid[vp[j].second][vp[j].first]=1;
                        if(mp.find( vp[j]  )!=mp.end()) break;
                    }
                }
                if(j!=N) continue;

                int cnt=1;
                for(j1=0; j1<n; j1++)
                {
                    int cn=0;
                    for(j2=0; j2<n; j2++)
                    {
                        cn+=grid[j1][j2];
                    }
                    if(cn>2) cnt=0;
                }
                if(cnt==0) continue;

                for(i=0;i<n;i++)
                for(j=i+1;j<n;j++)
                {
                    if(grid[i][j]) printf("%d %d\n",i+1,j+1);
                }
                return 0;

            }

        }
        printf("-1\n");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        if(vis[i]==0)
        {
            dfs(i);
            if(order1.size()!=3)
            {
                merge();
            }
            else
            {
                tree[0].push_back(order1[0]);
                tree[1].push_back(order1[1]);
                tree[2].push_back(order1[2]);
            }
            order1.clear();
        }
    }

    if(tree[0].size()!=1)
    {
        for(j=0;j<3;j++)
        for(i=0;i<tree[j].size();i++)
        {
            ans.push_back(tree[j][i]);
            //cout<<tree[j][i]+1<<" ";
        }
       // asdf

        tree[0].clear();
        tree[1].clear();
        tree[2].clear();
    }

    //asdf

    if(ans.size())
    {
        int x1=ans.back();ans.pop_back();
        int x2=ans.back();ans.pop_back();

        for(i=0;i<order.size();i+=2) ans.push_back(order[i]);
        ans.push_back(x2);

        for(i=1;i<order.size();i+=2) ans.push_back(order[i]);
        ans.push_back(x1);
    }
    else
    {
        memset(vis,0,sizeof(vis));
        for(i=0; i<order.size(); i+=2)
        {
            ans.push_back( order[i] );
            vis[i]=1;
        }

        for(i=1; i<order.size(); i+=2)
        {
            ans.push_back( order[i] );
            vis[i]=1;
            break;
        }

        for(i=((int)order.size())-1; i>=0; i--)
        {
            if(vis[i]==0) ans.push_back(order[i]);
        }

        if(tree[0].size()!=0)
        {
            int x1=ans.back();ans.pop_back();
            int x2=ans.back();ans.pop_back();

            ans.push_back(tree[0][0]);
            ans.push_back(x1);
            ans.push_back(tree[1][0]);
            ans.push_back(x2);
            ans.push_back(tree[2][0]);
        }
    }

    for(i=0; i<m; i++)
    {
        printf("%d %d\n",ans[i]+1,ans[(i+1)%ans.size()]+1);
    }

    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<assert.h>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9
#define asdf exit(0);

typedef long long LL;

vector<int> adj[100010];
map< pair<int,int>,int > mp;

int vis[100010];

vector<int> order;
vector<int> ans;

void dfs(int u)
{
    int i,v;
    vis[u]=1;
    order.push_back(u);
    for(i=0; i<adj[u].size(); i++)
    {
        v=adj[u][i];
        if(vis[v]) continue;
        dfs(v);
    }
}

int main()
{
   // freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int n,m,x,y,i,j,j1,j2;
    scanf("%d %d",&n,&m);

    for(i=0; i<m; i++)
    {
        scanf("%d %d",&x,&y);
        x--;
        y--;
        mp[make_pair(x,y)]=1;
        mp[make_pair(y,x)]=1;

        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    if(n<=4)
    {

        vector< pair<int,int> > vp;

        for(i=0; i<n; i++)
            for(j=i+1; j<n; j++)
            {
                vp.push_back(make_pair(i,j));
            }

        int grid[5][5];
        int N=vp.size();

        int got=0;
        for(i=0; i<(1<<N); i++)
        {
            if(__builtin_popcount(i)==m)
            {
                memset(grid,0,sizeof(grid));
                for(j=0; j<N; j++)
                {
                    grid[vp[j].first][vp[j].second]=1;
                    grid[vp[j].second][vp[j].first]=1;
                }

                int cnt=1;
                for(j1=0; j1<n; j1++)
                {
                    int cn=0;
                    for(j2=0; j2<n; j2++)
                    {
                        cn+=grid[j1][j2];
                        if(grid[j1][j2]==1 && mp.find( make_pair(j1,j2)  )!=mp.end() )
                        {
                            cnt=0;
                        }
                    }
                    if(cn>2)
                    {
                        cnt=0;
                    }
                }
                if(cnt==0) continue;

                for(i=0;i<n;i++)
                for(j=i+1;j<n;j++)
                {
                    if(grid[i][j]) printf("%d %d\n",i+1,j+1);
                }
                got=1;
                break;
            }

            if(got) break;
        }

        if(got==0)
        {
            printf("-1\n");
        }

        return 0;
    }

    for(i=0; i<n; i++)
    {
        if(vis[i]==0)
        {
            dfs(i);
        }
    }

   //for(i=0;i<n;i++) cout<<order[i]+1<<" ";
   // cout<<endl;
  //  asdf

    memset(vis,0,sizeof(vis));
    for(i=0; i<n; i+=2)
    {
        ans.push_back( order[i] );
        vis[i]=1;
    }

    for(i=1; i<n; i+=2)
    {
        ans.push_back( order[i] );
        vis[i]=1;
        break;
    }

    for(i=n-1; i>=0; i--)
    {
        if(vis[i]==0)
        {
            ans.push_back(order[i]);
        }
    }

    for(i=0; i<m; i++)
    {
        printf("%d %d\n",ans[i]+1,ans[(i+1)%ans.size()]+1);
    }

    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<assert.h>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9
#define asdf exit(0);

typedef long long LL;

vector<int> adj[100010];
map< pair<int,int>,int > mp;

int vis[100010];
int home[100010];

vector<int> ans;
vector<int> tree[3];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int n,m,x,y,i,j,j1,j2;
    scanf("%d %d",&n,&m);

    for(i=0; i<m; i++)
    {
        scanf("%d %d",&x,&y);
        x--;
        y--;
        mp[make_pair(x,y)]=1;
        mp[make_pair(y,x)]=1;

        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    if(n<=5)
    {
        vector< pair<int,int> > vp;
        for(i=0; i<n; i++)
            for(j=i+1; j<n; j++)
            {
                vp.push_back(make_pair(i,j));
            }

        int grid[6][6];
        int N=vp.size();

        for(i=0; i<(1<<N); i++)
        {
            if(__builtin_popcount(i)==m)
            {
                memset(grid,0,sizeof(grid));
                for(j=0; j<N; j++)
                {
                    if(i & (1<<j))
                    {
                        grid[vp[j].first][vp[j].second]=1;
                        grid[vp[j].second][vp[j].first]=1;
                        if(mp.find( vp[j]  )!=mp.end()) break;
                    }
                }
                if(j!=N) continue;

                int cnt=1;
                for(j1=0; j1<n; j1++)
                {
                    int cn=0;
                    for(j2=0; j2<n; j2++)
                    {
                        cn+=grid[j1][j2];
                    }
                    if(cn>2) cnt=0;
                }
                if(cnt==0) continue;

                for(i=0;i<n;i++)
                for(j=i+1;j<n;j++)
                {
                    if(grid[i][j]) printf("%d %d\n",i+1,j+1);
                }
                return 0;

            }

        }
        printf("-1\n");
        return 0;
    }

    vector<int> v;
    for(i=0;i<6;i++) v.push_back(i);

    for(i=0;i<725;i++)
    {

        for(j=0;j<6;j++)
        {
            x=v[j];
            y=v[(j+1)%6];

            if(mp.find(make_pair(x,y))!=mp.end()) break;
        }
        if(j==6) break;
        next_permutation(v.begin(),v.end());
    }

    for(i=0;i<3;i++)
    {
        tree[i].push_back(v[2*i]);
        tree[i].push_back(v[2*i+1]);

        home[ v[2*i] ]=i+1;
        home[ v[2*i+1] ]=i+1;
    }

    set<int> s;

    for(i=6;i<n;i++)
    {
        s.insert(1);
        s.insert(2);
        s.insert(3);

        for(j=0;j<adj[i].size();j++)
        {
            s.erase(  home [adj[i][j] ] );
        }

        set<int> :: iterator it=s.begin();

        home[ i ] = *it;
        tree[*it].push_back(i);
    }

    for(i=0;i<3;i++)
    {
        for(j=0;j<tree[i].size();j++)
        {
            ans.push_back(tree[i][j]);
        }
    }

    for(i=0; i<m; i++)
    {
        printf("%d %d\n",ans[i]+1,ans[(i+1)%ans.size()]+1);
    }

    return 0;
}


// I/O stream
#include <iostream>
#include <iomanip>

// Algorithms & Maths
#include <cmath>
#include <numeric>
#include <algorithm>

// C headers
#include <cstdlib>
#include <cstdio>

// String
#include <string>
#include <cstring>

// STL
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>

// Exeption
#include <exception>
#include <stdexcept>
#include <cassert>

using namespace std;

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define PQ priority_queue
#define GT(type) greater < type >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;
const int TT = 200;

int n, m;
int p[MAXN];
int ks[MAXN];
int edge[MAXN][2];

void init ();
void input ();
void work ();

int main()
{
	init();
	input();
	work();
}

void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	scanf ( "%d%d", &n, &m );

	int u, v;
	INIT ( ks, 0 );
	lp ( i, 0, m ){
		scanf ( "%d%d", &u, &v );
		edge[u][ks[u]++] = v;
		edge[v][ks[v]++] = u;
	}
}

void work ()
{
	// main work

	bool flag;
	lp ( _t, 0, TT ){
		lp ( i, 0, n ) p[i] = i + 1;
		random_shuffle ( p, p+n );
		flag = true;
		p[n] = p[0];
		lp ( i, 0, n ){
			lp ( j, 0, ks[p[i]] ){
				if ( p[i+1] == edge[p[i]][j] ){
					flag = false;
					break;
				}
			}
			if ( !flag ) break;
		}
		if ( flag ){
			lp ( i, 0, m ) printf ( "%d %d\n", p[i], p[i+1] );
			return;
		}
	}

	printf ( "-1\n" );
}


//ssense
#include<bits/stdc++.h>
#include<string.h>
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef unsigned long long ull;
typedef long long  ll;
using namespace std;
#define FOR(n) for(int i=0;i<n;i++)
#define vt vector
#define sz(a) (int)a.size()
#define MOD 1000000007
#define MOD2 998244353
#define MX 1000000000
#define NMAX 100005
#define MXL 1000000000000000000
#define PI 3.14159265
#define pb push_back
#define sc second
#define endl '\n'
#define fr first
#define int ll
vector<int> pf;
vector<int> d;
vector<int> adj[200030];
vector<int> dist;
bool nod[200030];
int ceildiv(int one, int two){
    if(one%two == 0)
    {
        return one/two;
    }
    else
    {
        return one/two+1;
    }
}void primeFactors(int n){
    while (n % 2 == 0)
    {
        pf.pb(2);
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            pf.pb(i);
            n = n/i;
        }
    }
    if (n > 2)
    {
        pf.pb(n);
    }
}int power(int n, int pow, int m){
    if(pow == 0) return 1;
    if(pow%2 == 0){ll x = power(n, pow/2, m);
        return (x*x)%m;}
    else return (power(n, pow-1, m)*n)%m;
}int gcd(int a, int b){
    if(!b)return a;
    return gcd(b,a%b);
}bool permutation(int arr[], int n){
    set<int> hash;
    int maxEle = 0;
    for (int i = 0; i < n; i++)
    {
        hash.insert(arr[i]);
        maxEle = max(maxEle, arr[i]);
    }
    if (maxEle != n)
    {
        return false;
    }
    if (hash.size()*1LL == n)
    {
        return true;
    }
    return false;
}void divis(int n){
    for(int i = 1; i <= sqrt(n); i++)
    {
        if(n%i == 0)
        {
            d.pb(i);
            if(i*i != n)
            {
                d.pb(n/i);
            }
        }
    }
    sort(d.begin(), d.end());
}int factorial(int n, int mod){
    if(n > 1)
        return (n*factorial(n - 1, mod))%mod;
    else
        return 1;
}int lcm(int a, int b){
    return (a*b)/gcd(a, b);
}int checkPrimeNumber(int n){
    bool flag = false;

    for(int i = 2; i <= sqrt(n); ++i)
    {
        if(n%i == 0)
        {
            flag = true;
            break;
        }
    }
    return flag;
}string to_string(char c){return string(1, c);}string to_string(bool b){return b?"true":"false";}string to_string(const char* s){return string(s);}string to_string(string s){return s;}string to_string(vt<bool>v){string res;FOR(sz(v))res+=char('0'+v[i]);return res;}template<class T> string to_string(T v){bool f=1;string res;for(auto x:v){if(!f)res+=' ';f=0;res+=to_string(x);}return res;}template<class A> void write(A x){cout << to_string(x);}template<class H, class... T> void write(const H& h, const T&... t){write(h);write(t...);}void print(){write("\n");}template<class H, class... T> void print(const H& h, const T&... t) { write(h);if(sizeof...(t))write(' ');print(t...);}
void dfs(int u){
    nod[u] = true;
    for(auto x : adj[u])
    {
        if(nod[x])continue;
        nod[x] = true;
        dfs(x);
    }
}void bfs(int s) {
    dist.assign(200005, -1);
    queue<int> q;
    dist[s] = 0; q.push(s);
    while (q.size()) {
        int u = q.front(); q.pop();
        for (int v : adj[u]) {
            if (dist[v] == -1) {
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }
}

void solve(){
    string s;
    cin >> s;
    set<int> st;
    int q = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == '?')
        {
            q++;
        }
    }
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] >= 'A' && s[i] <= 'J')
        {
            st.insert(s[i]-'A');
        }
    }
    int x = power(10, q, MXL);
    int y = factorial(10-st.size(), MXL);
    if(s[0] == '?' || (s[0] >= 'A' && s[0] <= 'Z'))
    {
        cout << (3628800/y)*x/10*9 << endl;
    }
    else
    {
        cout << (3628800/y)*x << endl;
    }
}

int32_t main() {
    startt
    solve();
}


//ssense
#include<bits/stdc++.h>
#include<string.h>
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef unsigned long long ull;
typedef long long  ll;
using namespace std;
#define FOR(n) for(int i=0;i<n;i++)
#define vt vector
#define sz(a) (int)a.size()
#define MOD 1000000007
#define MOD2 998244353
#define MX 1000000000
#define NMAX 100005
#define MXL 1000000000000000000
#define PI 3.14159265
#define pb push_back
#define sc second
#define endl '\n'
#define fr first
#define int ll
vector<int> pf;
vector<int> d;
vector<int> adj[200030];
vector<int> dist;
bool nod[200030];
int ceildiv(int one, int two){
    if(one%two == 0)
    {
        return one/two;
    }
    else
    {
        return one/two+1;
    }
}void primeFactors(int n){
    while (n % 2 == 0)
    {
        pf.pb(2);
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            pf.pb(i);
            n = n/i;
        }
    }
    if (n > 2)
    {
        pf.pb(n);
    }
}int power(int n, int pow, int m){
    if(pow == 0) return 1;
    if(pow%2 == 0){ll x = power(n, pow/2, m);
        return (x*x)%m;}
    else return (power(n, pow-1, m)*n)%m;
}int gcd(int a, int b){
    if(!b)return a;
    return gcd(b,a%b);
}bool permutation(int arr[], int n){
    set<int> hash;
    int maxEle = 0;
    for (int i = 0; i < n; i++)
    {
        hash.insert(arr[i]);
        maxEle = max(maxEle, arr[i]);
    }
    if (maxEle != n)
    {
        return false;
    }
    if (hash.size()*1LL == n)
    {
        return true;
    }
    return false;
}void divis(int n){
    for(int i = 1; i <= sqrt(n); i++)
    {
        if(n%i == 0)
        {
            d.pb(i);
            if(i*i != n)
            {
                d.pb(n/i);
            }
        }
    }
    sort(d.begin(), d.end());
}int factorial(int n, int mod){
    if(n > 1)
        return (n*factorial(n - 1, mod))%mod;
    else
        return 1;
}int lcm(int a, int b){
    return (a*b)/gcd(a, b);
}int checkPrimeNumber(int n){
    bool flag = false;

    for(int i = 2; i <= sqrt(n); ++i)
    {
        if(n%i == 0)
        {
            flag = true;
            break;
        }
    }
    return flag;
}string to_string(char c){return string(1, c);}string to_string(bool b){return b?"true":"false";}string to_string(const char* s){return string(s);}string to_string(string s){return s;}string to_string(vt<bool>v){string res;FOR(sz(v))res+=char('0'+v[i]);return res;}template<class T> string to_string(T v){bool f=1;string res;for(auto x:v){if(!f)res+=' ';f=0;res+=to_string(x);}return res;}template<class A> void write(A x){cout << to_string(x);}template<class H, class... T> void write(const H& h, const T&... t){write(h);write(t...);}void print(){write("\n");}template<class H, class... T> void print(const H& h, const T&... t) { write(h);if(sizeof...(t))write(' ');print(t...);}
void dfs(int u){
    nod[u] = true;
    for(auto x : adj[u])
    {
        if(nod[x])continue;
        nod[x] = true;
        dfs(x);
    }
}void bfs(int s) {
    dist.assign(200005, -1);
    queue<int> q;
    dist[s] = 0; q.push(s);
    while (q.size()) {
        int u = q.front(); q.pop();
        for (int v : adj[u]) {
            if (dist[v] == -1) {
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }
}

void solve(){
    string s;
    cin >> s;
    set<int> st;
    int q = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == '?')
        {
            q++;
        }
    }
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] >= 'A' && s[i] <= 'J')
        {
            st.insert(s[i]-'A');
        }
    }
    if(st.size() == 0)
    {
        if(s[0] == '?')
        {
            cout << 9;
            for(int i = 0; i < q-1; i++)
            {
                cout << 0;
            }
        }
        else
        {
            cout << 1;
            for(int i = 0; i < q; i++)
            {
                cout << 0;
            }
        }
        return;
    }
    int y = factorial(10-st.size(), MXL);
    if(s[0] == '?' || (s[0] >= 'A' && s[0] <= 'Z'))
    {
        cout << (3628800/y)*9/10;
        for(int i = 0; i < q; i++)
        {
            cout << 0;
        }
    }
    else
    {
        cout << (3628800/y);
        for(int i = 0; i < q; i++)
        {
            cout << 0;
        }
    }
}

int32_t main() {
    startt
    solve();
}


//ssense
#include<bits/stdc++.h>
#include<string.h>
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef unsigned long long ull;
typedef long long  ll;
using namespace std;
#define FOR(n) for(int i=0;i<n;i++)
#define vt vector
#define sz(a) (int)a.size()
#define MOD 1000000007
#define MOD2 998244353
#define MX 1000000000
#define NMAX 100005
#define MXL 1000000000000000000
#define PI 3.14159265
#define pb push_back
#define sc second
#define endl '\n'
#define fr first
#define int ll
vector<int> pf;
vector<int> d;
vector<int> adj[200030];
vector<int> dist;
bool nod[200030];
int ceildiv(int one, int two){
    if(one%two == 0)
    {
        return one/two;
    }
    else
    {
        return one/two+1;
    }
}void primeFactors(int n){
    while (n % 2 == 0)
    {
        pf.pb(2);
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            pf.pb(i);
            n = n/i;
        }
    }
    if (n > 2)
    {
        pf.pb(n);
    }
}int power(int n, int pow, int m){
    if(pow == 0) return 1;
    if(pow%2 == 0){ll x = power(n, pow/2, m);
        return (x*x)%m;}
    else return (power(n, pow-1, m)*n)%m;
}int gcd(int a, int b){
    if(!b)return a;
    return gcd(b,a%b);
}bool permutation(int arr[], int n){
    set<int> hash;
    int maxEle = 0;
    for (int i = 0; i < n; i++)
    {
        hash.insert(arr[i]);
        maxEle = max(maxEle, arr[i]);
    }
    if (maxEle != n)
    {
        return false;
    }
    if (hash.size()*1LL == n)
    {
        return true;
    }
    return false;
}void divis(int n){
    for(int i = 1; i <= sqrt(n); i++)
    {
        if(n%i == 0)
        {
            d.pb(i);
            if(i*i != n)
            {
                d.pb(n/i);
            }
        }
    }
    sort(d.begin(), d.end());
}int factorial(int n, int mod){
    if(n > 1)
        return (n*factorial(n - 1, mod))%mod;
    else
        return 1;
}int lcm(int a, int b){
    return (a*b)/gcd(a, b);
}int checkPrimeNumber(int n){
    bool flag = false;

    for(int i = 2; i <= sqrt(n); ++i)
    {
        if(n%i == 0)
        {
            flag = true;
            break;
        }
    }
    return flag;
}string to_string(char c){return string(1, c);}string to_string(bool b){return b?"true":"false";}string to_string(const char* s){return string(s);}string to_string(string s){return s;}string to_string(vt<bool>v){string res;FOR(sz(v))res+=char('0'+v[i]);return res;}template<class T> string to_string(T v){bool f=1;string res;for(auto x:v){if(!f)res+=' ';f=0;res+=to_string(x);}return res;}template<class A> void write(A x){cout << to_string(x);}template<class H, class... T> void write(const H& h, const T&... t){write(h);write(t...);}void print(){write("\n");}template<class H, class... T> void print(const H& h, const T&... t) { write(h);if(sizeof...(t))write(' ');print(t...);}
void dfs(int u){
    nod[u] = true;
    for(auto x : adj[u])
    {
        if(nod[x])continue;
        nod[x] = true;
        dfs(x);
    }
}void bfs(int s) {
    dist.assign(200005, -1);
    queue<int> q;
    dist[s] = 0; q.push(s);
    while (q.size()) {
        int u = q.front(); q.pop();
        for (int v : adj[u]) {
            if (dist[v] == -1) {
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }
}

void solve(){
    string s;
    cin >> s;
    set<int> st;
    int q = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == '?')
        {
            q++;
        }
    }
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] >= 'A' && s[i] <= 'J')
        {
            st.insert(s[i]-'A');
        }
    }
    int y = factorial(10-st.size(), MXL);
    if(s[0] == '?' || (s[0] >= 'A' && s[0] <= 'Z'))
    {
        cout << (3628800/y)/10*9;
        for(int i = 0; i < q; i++)
        {
            cout << 0;
        }
    }
    else
    {
        cout << (3628800/y);
        for(int i = 0; i < q; i++)
        {
            cout << 0;
        }
    }
}

int32_t main() {
    startt
    solve();
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
//#include<fstream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<string>
#include<map>
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int, int> P;
typedef long long ll;
#define fi first
#define se scond
#define me(x) memset(x, -1, sizeof(x))
#define mem(x) memset(x, 0, sizeof(x))
#define N 100000+5
int a[15];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll i, j, k;
    ll n, m, cou=0, co=0;
    string s;
    cin>>s;
    n=s.length();
    for(i=0; i<n; i++)
    {
        if(s[i]>='A' && s[i]<='J')
        {
            k=s[i]-'A';
            a[k]=1;
        }
        else if(s[i]=='?')
            cou++;
    }
    for(i=0; i<15; i++)
        if(a[i]) co++;
    k=10;
    if(s[0]>='A' && s[0]<='J')
        k=9;
    co--;
    m=9;
    ll cou1=1;
    if(co<0) cou1=0;
    for(i=0; i<co; i++)
    {
        cou1*=m;
        m--;
    }
    cou1*=k;
//cout<<cou1<<endl;

    if(!cou1) cou1=1;

    ll cou2=1;
    cou--;
    if(cou<0) cou2=0;
    k=10;
    if(s[0]=='?')
        k=9;
    cou2*=k;

    if(!cou2) cou2=1;

    cou1*=cou2;
//cout<<cou1<<endl;
    if(!cou1) cou1=1;
    cout<<cou1;
    for(i=0; i<cou; i++)
        cout<<0;
    cout<<endl;
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
//#include<fstream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<string>
#include<map>
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int, int> P;
typedef long long ll;
#define fi first
#define se scond
#define me(x) memset(x, -1, sizeof(x))
#define mem(x) memset(x, 0, sizeof(x))
#define N 100000+5
int a[15];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll i, j, k;
    ll n, m, cou=0, co=0;
    string s;
    cin>>s;
    n=s.length();
    for(i=0; i<n; i++)
    {
        if(s[i]>='A' && s[i]<='J')
        {
            k=s[i]-'A';
            a[k]=1;
        }
        else if(s[i]=='?')
            cou++;
    }
    for(i=0; i<15; i++)
        if(a[i]) co++;
    k=10;
    if(s[0]>='A' && s[0]<='J')
        k=9;
    co--;
    m=9;
    ll cou1=1;
    for(i=0; i<cou; i++)
        cou1*=10;
    if(!cou1) cou1=1;
    for(i=0; i<co; i++)
    {
        cou1*=m;
        m--;
    }
    cou1*=k;
    cout<<cou1<<endl;
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
//#include<fstream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<string>
#include<map>
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int, int> P;
typedef long long ll;
#define fi first
#define se scond
#define me(x) memset(x, -1, sizeof(x))
#define mem(x) memset(x, 0, sizeof(x))
#define N 100000+5
int a[15];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll i, j, k;
    ll n, m, cou=0, co=0;
    string s;
    cin>>s;
    n=s.length();
    for(i=0; i<n; i++)
    {
        if(s[i]>='A' && s[i]<='J')
        {
            k=s[i]-'A';
            a[k]=1;
        }
        else if(s[i]=='?')
            cou++;
    }
    for(i=0; i<15; i++)
        if(a[i]) co++;
    k=10;
    if(s[0]>='A' && s[0]<='J')
        k=9;
    co--;
    m=9;
    ll cou1=1;
    if(co<0) cou1=0;
    for(i=0; i<co; i++)
    {
        cou1*=m;
        m--;
    }
    cou1*=k;
//cout<<cou1<<endl;
    if(!cou1) cou1=1;
    ll cou2=1;
    cou--;
    if(cou<0) cou2=0;
    k=10;
    if(s[0]=='?')
        k=9;
    for(i=0; i<cou; i++)
        cou2*=10;
    cou2*=k;
    if(!cou2) cou2=1;
    cou1*=cou2;
//cout<<cou1<<endl;
    if(!cou1) cou1=1;
    cout<<cou1<<endl;
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
//#include<fstream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<string>
#include<map>
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int, int> P;
typedef long long ll;
#define fi first
#define se scond
#define me(x) memset(x, -1, sizeof(x))
#define mem(x) memset(x, 0, sizeof(x))
#define N 100000+5
int a[15];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll i, j, k;
    ll n, m, cou=0, co=0;
    string s;
    cin>>s;
    n=s.length();
    for(i=0; i<n; i++)
    {
        if(s[i]>='A' && s[i]<='J')
        {
            k=s[i]-'A';
            a[k]=1;
        }
        else if(s[i]=='?')
            cou++;
    }
    for(i=0; i<15; i++)
        if(a[i]) co++;
    k=10;
    if(s[0]>='A' && s[0]<='J')
        k=9;
    co--;
    m=9;
    ll cou1=1;
    if(co<0) cou1=0;
    for(i=0; i<co; i++)
    {
        cou1*=m;
        m--;
    }
    cou1*=k;

    if(!cou1) cou1=1;
    ll cou2=1;
    cou--;
    if(cou<0) cou2=0;
    k=10;
    if(s[0]=='?')
        k=9;
    for(i=0; i<cou; i++)
        cou2*=10;
    cou2*=k;
    cou1*=cou2;
    if(!cou1) cou1=1;
    cout<<cou1<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define gcd(a,b) __gcd(a,b)
#define ll long long
#define ms(x,a) memset(x,a,sizeof(x))
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repp(i,a,b) for(int i=a;i>=b;i--)
#define sd(x) scanf("%d",&x)
#define sdd(x,y) scanf("%d%d",&x,&y)
#define debug() cout<<"***"<<endl;
using namespace std;
const int maxn=1e3+10;
int n,m;
char ss[maxn];
map<char,int>mp;
int main()
{
    scanf("%s",ss+1);
    int len=strlen(ss+1),cnt=0,cnt1=0;
    for(int i=1;i<=len;i++){
        if(ss[i]!='?'&&mp[ss[i]]==0&&ss[i]>='A'&&ss[i]<='J'){
            cnt++;
            mp[ss[i]]++;
        }
        if(ss[i]=='?'){
            cnt1++;
        }
    }
    ll tt=(ll)(10-cnt+1);
    ll ans=1;
    for(int i=1;i<=cnt;i++){
        ans*=tt;
    }
//    cout<<cnt<<" "<<ans<<endl;
    if(cnt1){
        for(int i=1;i<=cnt1;i++){
            ans*=(ll)10;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define gcd(a,b) __gcd(a,b)
#define ll long long
#define ms(x,a) memset(x,a,sizeof(x))
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repp(i,a,b) for(int i=a;i>=b;i--)
#define sd(x) scanf("%d",&x)
#define sdd(x,y) scanf("%d%d",&x,&y)
#define debug() cout<<"***"<<endl;
using namespace std;
const int maxn=1e3+10;
int n,m;
char ss[maxn];
map<char,int>mp;
int main()
{
    scanf("%s",ss+1);
    int len=strlen(ss+1),cnt=0,cnt1=0,cnt2=0,maxx=0;
    for(int i=1;i<=len;i++){
        if(ss[i]>='A'&&ss[i]<='J'){
            if(mp[ss[i]]==0)cnt++;
            mp[ss[i]]++;
            maxx=max(maxx,mp[ss[i]]);
        }
        if(ss[i]=='?'){
            cnt1++;
        }
        else if(ss[i]=='0'){
            cnt2++;
        }
    }
    ll tt=(ll)(10-cnt+1);
    ll ans=1;
    for(int i=1;i<=cnt;i++){
        ans*=tt;
    }
//    cout<<cnt<<" "<<ans<<endl;
    if(cnt1){
        for(int i=1;i<=cnt1;i++){
            ans*=(ll)10;
        }
    }
    if(cnt2+cnt1+maxx==len){
        ans--;
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define gcd(a,b) __gcd(a,b)
#define ll long long
#define ms(x,a) memset(x,a,sizeof(x))
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repp(i,a,b) for(int i=a;i>=b;i--)
#define sd(x) scanf("%d",&x)
#define sdd(x,y) scanf("%d%d",&x,&y)
#define debug() cout<<"***"<<endl;
using namespace std;
const int maxn=1e5+10;
int n,m;
char ss[maxn];
map<char,int>mp;
int main(){
    scanf("%s",ss+1);
    string tt;
    int len=strlen(ss+1);
    ll ans=1,k=10;
    if(ss[1]>='A'&&ss[1]<='J'){
        ans=k=9;
    }
    else if(ss[1]=='?')ans=9;
    mp[ss[1]]=1;
    for(int i=2;i<=len;i++){
        if(ss[i]=='?')tt+='0';
        else if(!mp[ss[i]]&&ss[i]>='A'&&ss[i]<='J')ans*=k,k--,mp[ss[i]]=1;
    }
    cout<<ans<<tt<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define gcd(a,b) __gcd(a,b)
#define ll long long
#define ms(x,a) memset(x,a,sizeof(x))
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repp(i,a,b) for(int i=a;i>=b;i--)
#define sd(x) scanf("%d",&x)
#define sdd(x,y) scanf("%d%d",&x,&y)
#define debug() cout<<"***"<<endl;
using namespace std;
const int maxn=1e3+10;
int n,m;
char ss[maxn];
map<char,int>mp;
int main()
{
    scanf("%s",ss+1);
    int len=strlen(ss+1),cnt=0,cnt1=0;
    for(int i=1;i<=len;i++){
        if(ss[i]>='A'&&ss[i]<='J'){
            if(mp[ss[i]]==0)cnt++;
            mp[ss[i]]++;
        }
        if(ss[i]=='?'){
            cnt1++;
        }
    }
    ll tt=(ll)(10-cnt+1);
    ll ans=tt;
    if(ss[1]>='A'&&ss[1]<='J'){
        ans--;
    }
    for(int i=1;i<=cnt-1;i++){
        ans*=tt;
    }
//    cout<<cnt<<" "<<ans<<endl;
    if(cnt1){
        if(ss[0]=='?')ans*=(ll)9;
        else ans*=(ll)10;
        for(int i=1;i<=cnt1-1;i++){
            ans*=(ll)10;
        }
    }
    cout<<ans<<endl;
    return 0;
}


/* *****fireice**** */

#include<bits/stdc++.h>

#define ll long long int
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pb push_back
#define el '\n'
#define N 1000000007
#define re return
#define F first
#define S second
#define L length
#define PI 3.14159265
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int i=0;i<n;i++)
#define forf(i,x,n) for(int i=x;i<n;i++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
#define take(a,n) forup(i,n) cin>>a[i];
using namespace std;

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(int a, int m)
{
    int x, y;
    int g = gcdExtended(a, m, &x, &y);
        // m is added to handle negative x
    ll res = ((ll)x%m + (ll)m) % m;

    return res;
}

ll poww(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return poww(x*x,n/2);
    else                             //n is odd
        return x*poww(x*x,(n-1)/2);
}

ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

inline ll max(ll a, ll b)
{
  if(a>b) re a;
  else re b;
}

inline ll min(ll a, ll b)
{
  if(a>b) re b;
  else re a;
}

int gcd(int a, int b)
{
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    else return gcd(a, b-a);
}

ll ncr(int n,int r)
{
  ll ans=1;
  r=min(r,n-r);
  forup(i,r)
  {
    ans=(ans*(n-i)/(i+1))%N;
  }
  re ans;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int t=1;
  //cin>>t;
  while(t--)
  {
    ll n,m,k;
    // cin>>n;
    string s;
    set<char> v;
    cin>>s;
    string a="";
    // cout<<"YES";

    forup(i,s.L())
    {
      if(s[i]<='J' && s[i]>='A') v.insert(s[i]);
    }

    ll ans=1;
    forup(i,v.size()) ans*=10-i;
    if(s[0]<='J' && s[0]>='A') ans*=9,ans/=10;
    if(s[0]=='?') ans*=9;

    while(ans>0)
    {
      a+=(char)(ans%10)+48;
      ans/=10;
    }
    reverse(all(a));

    forf(i,1,s.L())
    {
      if(s[i]=='?') a+='0';
    }

    cout<<a<<el;
  }

  return 0;
}


/* *****fireice**** */

#include<bits/stdc++.h>

#define ll long long int
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pb push_back
#define el '\n'
#define N 1000000007
#define re return
#define F first
#define S second
#define L length
#define PI 3.14159265
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int i=0;i<n;i++)
#define forf(i,x,n) for(int i=x;i<n;i++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
#define take(a,n) forup(i,n) cin>>a[i];
using namespace std;

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(int a, int m)
{
    int x, y;
    int g = gcdExtended(a, m, &x, &y);
        // m is added to handle negative x
    ll res = ((ll)x%m + (ll)m) % m;

    return res;
}

ll poww(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return poww(x*x,n/2);
    else                             //n is odd
        return x*poww(x*x,(n-1)/2);
}

ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

inline ll max(ll a, ll b)
{
  if(a>b) re a;
  else re b;
}

inline ll min(ll a, ll b)
{
  if(a>b) re b;
  else re a;
}

int gcd(int a, int b)
{
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    else return gcd(a, b-a);
}

ll ncr(int n,int r)
{
  ll ans=1;
  r=min(r,n-r);
  forup(i,r)
  {
    ans=(ans*(n-i)/(i+1))%N;
  }
  re ans;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int t=1;
  //cin>>t;
  while(t--)
  {
    ll n,m,k;
    // cin>>n;
    string s;
    set<char> v;
    cin>>s;
    // cout<<"YES";
    forup(i,s.L())
    {
      if(s[i]>='A' && s[i]<='J')
      v.insert(s[i]);
    }
    ll ans=1;

    // cout<<"YES";
    if(v.size()>1)
    forup(i,v.size())
    {
      ans*=10-i;
    }
    if(s[0]<='J' && s[0]>='A')
    {
      ans*=9;
      ans/=10;
    }
    forup(i,s.L())
    {
      if(s[i]=='?')
      {
        if(i==0) ans*=9;
        else ans*=10;
      }
    }

    cout<<ans<<el;
  }

  return 0;
}