#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)

int main(){
    int n,m;
    cin>>n>>m;
    int ans[n];
    int s[m], c[m];
    int flag[n]={};
    for(int i=0;i<n;i++) ans[i]=0;
    rep(i,m) {
        cin>>s[i]>>c[i];
    }
    rep(i,m){
        if(flag[s[i]-1]==0){
            ans[s[i]-1]=c[i];
            flag[s[i]-1]++;
        }
        else{
            if(ans[s[i]-1]==c[i]){
                ans[s[i]-1]=c[i];
                flag[s[i]-1]++;
            }
            else{
                cout<<-1<<endl;
                return 0;
            }
        }
    }
    if(n==1){
        cout<<ans[0]<<endl;
        return 0;
    }
    else{
        if(ans[0]==0){
            cout<<-1<<endl;
            return 0;
        }
        rep(i,n){
            cout<<ans[i];
        }
        cout<<endl;
        return 0;
    }

}