#include<iostream>
#include<string>
 
using namespace std;
 
int main() {
	int N,M;
	int s,c;
	int ans[3];
	bool flag = false;
	cin >> N >> M;
	for(int i=0;i<3;i++)ans[i] = -1;
	for(int i=0;i<M;i++){
		cin >> s >> c;
		if(ans[s-1]==-1 || ans[s-1]==c){
			ans[s-1]=c;
		}else{
			flag = true;
		}
	}
	if(flag || ans[0]==0){
		cout << "-1" << endl;;
	}else{
		if(ans[0]==-1){
			if(N == 1){
				cout << "0" << endl;
				return;
			}
			ans[0]=1;
		}
		for(int i=1;i<N;i++){
			if(ans[i]==-1){
				ans[i]=0;
			}
			ans[0]=ans[0]*10+ans[i];
		}
		cout << ans[0] << endl;
	}
	return 0;
}
