#include<iostream>
#include<algorithm>
 using namespace std;
 int a[4];
 int main()
 {
 	int n,m,x,y,flag=0;
 	cin>>n>>m;
	a[1]=a[2]=a[3]=-1;
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		if(a[x]!=-1&&a[x]!=y){
			flag=1;
			break;
		} 
		a[x]=y;
	}
	if(flag==1){
		cout<<-1<<endl;
		return 0;
	}
	if(a[1]==0&&n!=1){
		cout<<-1<<endl;
		return 0;
	}
	if(n==1&&a[1]==-1){
		cout<<0<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++){
		if(a[i]==-1&&i==1){
			cout<<"1";
			continue;
		} 
		if(a[i]==-1) cout<<"0";
		else cout<<a[i];
	}
 }