#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

/* ユークリッドの互除法 最大公約数*/
/*ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
*/


/*最小公倍数*/
/*
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
*/

/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll n,m;
    cin>>n>>m;
    if(n==1&&m==0){
        cout<<0<<endl;
        exit(0);
    }
    vector<pair<ll,ll>>p;
    string o="";
    for(ll i=0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        p.push_back(make_pair(a,b));
    }
    sort(p.begin(),p.end());
    for(ll i=0;i<m-1;i++){
        if(p[i].first==p[i+1].first
        &&p[i].second!=p[i+1].second){
            cout<<-1<<endl;
            exit(0);
        }
    }
    ll s=0;
    bool flag=true;
    ll k=1;
    ll a1=-1,a2=-1,a3=-1;
    for(ll i=0;i<m;i++){
        if(a1==-1&&p[i].first==1){
            a1=p[i].second;
            if(n==1){
                cout<<a1<<endl;
                exit(0);
            }
        }
        else if(a2==-1&&p[i].first==2){
            a2=p[i].second;
        }
        else if(a3==-1&&p[i].first==3){
            a3=p[i].second;
        }
        /*
        else if(i==m-1&&a1==-1){
            cout<<-1<<endl;
            exit(0);
        }
        else if(i==m-1&&a1==0){
            cout<<-1<<endl;
            exit(0);
        }
        */

    }
    if(n==1&&a1==0){
        cout<<0<<endl;
        exit(0);
    }
    if(n!=1&&a1==0){
        cout<<-1<<endl;
        exit(0);
    }
    if(n!=1&&a1==-1){
        a1=1;
    }

    if(a2==-1){
        a2=0;
    }
    if(a3==-1){
        a3=0;
    }
    if(n==1){
        o=to_string(a1);
    }
    else if(n==2){
        o=to_string(a1)+to_string(a2);
    }
    else if(n==3){
        o=to_string(a1)+to_string(a2)+to_string(a3);
    }

    //o=to_string(a1)+to_string(a2)+to_string(a3);
    cout<<o<<endl;




    

    

}

Measured memory_bytes: 256