#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ll long long
#define  fs first
#define  sc second
int main(){
    ll n,m;cin>>n>>m;
    vector<ll> s(m),c(m);
    vector<ll> min(n,10);
    string ans;
    vector<char> cs(n,'0');
    REP(i,m) {
        cin>>s[i]>>c[i];
        s[i]--;
    }
    if(n==1){
        int min=c[0];
        char ans;
        if(m>0){
            REP(i,m){
                if(c[i]<min)min=c[i];
            }
        }
        else min=0;
        ans=min+'0';
        cout << ans << endl;
        return 0;
    }
    bool on=false;
    REP(i,m){
        if(s[i]==0 && c[i]>0){
            on=true;
        }
    }
    if(!on) {
        cout<<"-1"<<endl;
        return 0;
    }
    vector<ll> freq(n,-1);
    REP(i,m){
        REP(j,m){
            if(freq[s[i]==-1])freq[s[i]]=c[i];
            else if(freq(s[i])==c[i]) continue;
            else{
                cout << -1 << endl;
                return 0;
            }
        }
    }
    REP(i,m){
        if(s[i )
    }
    REP(i,m){
        cs[s[i]]=min[s[i]]+'0';
    }
    for(char tmp : cs) ans.push_back(tmp);
    cout<<ans<<endl;
    return 0;
}
