#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(n);
    vector<ll> c(n);
    REP(i,m){
        cin>>s[i]>>c[i];
        s[i]--;
    }
    vector<char> pre(n,'0');
    vector<ll> cnt(n,-1);
    string ans;
    bool ok =true;
    REP(i,m){
        if(cnt[s[i]==-1]) cnt[s[i]]=c[i];
        else if(cnt[s[i]]==c[i]) continue;
        else {
            ans="-1";
            ok=false;
            break;
        }
    }
    if(ok){
        REP(i,m) pre[s[i]]=c[i]+'0';
        for(auto tmp:pre) ans.push_back(tmp);
        if(ans[0]=='0' && n>1) ans="-1";
    }

    cout << ans << endl;
    return 0;
}