#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int  n,m,a[10],b[10];
int s,c;
 
 
int main(){
	while(cin>>n>>m){
		for(int i=1;i <= 5;i++) a[i]=-1;
		if(n==1&&m==0){cout<<0<<end;return 0;}
		for(int i=1;i <= m;i++){
			cin>>s>>c;
			if(s == 1 && c == 0 && n!=1 ) n=-1;
			if(a[s]!=-1&&a[s]!=c) n=-1;
			a[s]=c;
		}	
		if(n == -1){cout<<-1<<endl;return 0;}
 
		if(a[1] == -1) a[1]=1;
 
		for(int i=1;i <= n;i++){
			if(a[i]==-1)a[i]=0;
			cout<<a[i];
		}
		cout<<endl;
	}
 
}