#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int x[n]={};
    int s[m],c[m];
    for(int i=0;i<m;i++){
        cin>>s[i]>>c[i];
        if(x[s[i]-1]==0)
            x[s[i]-1]=c[i];
        else if(x[s[i]-1]!=c[i]){
            cout<<"-1"<<endl;
            return 0;
        }
    }
    if(n>1 && x[0]==0)x[0]=1;
    int a=1,b=0;
    for(int i=n-1;i>=0;i--){
        b+=a*x[i];
        a*=10;
    }
    cout<<b<<endl;
    return 0;
}