#include<bits/stdc++.h>
#define hell (int)(1e9+7)
#define int long long int
#define inf 1000000000000

using namespace std;

void solve(){
    int n,m;
    cin>>n>>m;
    map <int,int> mp;
    bool f=true;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        x--;
        if(mp.count(x)&&mp[x]!=y)
            f=false;
        mp[x]=y;
    }
    if(!f){
        cout<<-1;
        return;
    }
    for(int i=0;i<pow(10,n);i++){
        string s=to_string(i);
        f=true;
        for(auto &x:mp){
            if(x.first>=s.length()||&&(s[x.first]-'0')!=x.second)
                f=false;
        }
        if(f){
            cout<<i;
            return;
        }
    }
    cout<<-1;
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t,c;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}
