#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include <cmath>
using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    int s[M],c[M],num[N],hantei=1,ans=0;
    for (int i=0;i<N;i++){
        num[i]=-1;
    }
    for (int i=0;i<M;i++){
        cin>>s[i]>>c[i];
        if (num[s[i]-1]==-1) num[s[i]-1]=c[i];
        else if (num[s[i]-1]!=c[i]) hantei=hantei*0;
        if (N>=2){
            if (s[i]==1&&c[i]==0) hantei=hantei*0;
        } 
    }
    for (int i=0;i<N;i++){
        if (num[i]==-1){
            if (i==0) {
                if (M==0&&N=1)num[0]=0;
                else num[0]=1;
            }
            else num[i]=0;
        }
        ans+=pow(10,N-i-1)*num[i];
    }
    if (hantei==0) cout<<"-1"<<endl;
    else cout<<ans<<endl;
}