#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF=1001001001;

int main(void){
    // Your code here!
    int n,m;
    cin>>n>>m;
    vector<int> s(m);
    vector<int> c(m);
    rep(i,m) {cin>>s[i]>>c[i]; s[i]--;}
    int ans=-1;
    for(int j=0;j<1000;j++){
        int x=0;
        string t=to_string(j);
        rep(i,m){
            string y=to_string(c[i]);
        if(t.size()==n&&t[s[i]]==y[0]){
            x++;
        }
        }
        if(x==m){ ans=j; break;}
    }
    cout<<ans<<endl;
}
