#include "include.cpp"
#include "include/math.cpp"
#include "include/tmp.cpp"

using namespace std;

signed main (){
	int ans = 0;
	int n,m;
	cin >> n >> m;
	vector<pair<int,int>> sc(m);
	vector<int> num(n,0);
	int flag = 0;
	int digit = 0;
	rap(i,m){
		cin >> sc.at(i).first >> sc.at(i).second;
		num[sc[i].first-1] = sc[i].second;
	}
	rap(i,m){
		if(num[sc[i].first-1] != sc[i].second){
			flag = 1;
		}
	}
	if(m>1){
		if(num[0]==0){
			flag = 1;
		}
	}
	if(flag==1){
		cout<<-1<<endl;
	}else{
		int ans = 0;
		rap(i,n){
			ans += num[i] * pow(10,m-1-i);
		}
		cout<<ans<<endl;
	}
	return 0;
}