#include "bits/stdc++.h"
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P =pair<int,int>;

int main(){
    int n,m,k;
    k=0;
    cin >> n >> m ;
    vector <int> s(m),c(m);
    string newans="";
    
    rep(i,m){
        cin >> s[i] >> c[i];
    }

    vector <int> ans(n+1,-1);

    rep(i,m){
        
        if (ans[s[i]]!=-1 and ans[s[i]]!=c[i]){
            k=1;
            break;
        }
        else{
            ans[s[i]]=c[i];
        }
    }

    
    if (ans[1]==0){
        k=2;
    }
    if (ans[1]==-1){
        ans[1]=1;
    }
    if (k==0){
        rep(i+1,n){
            if (ans[i+1]==-1){
                ans[i+1]=0;
            }
            
            newans=newans+to_string(ans[i+1]);
        }
        cout << newans << endl;
    }
    else{
        cout << -1 << endl;
    }
    

    return 0;
}