#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,-1);
	int flag = 0;
	int digit = 0;
	rap(i,m){
		cin >> sc.at(i).first >> sc.at(i).second;
		if(num[sc[i].first-1]==-1){
			num[sc[i].first-1] = sc[i].second;
		}else{
			if(num[sc[i].first-1] != sc[i].second){
				flag = 1;
			}
		}
	}

	rap(i,n){
		if(num[i] != -1){
			ans += num[i] * pow(10,n-1-i);
		}
	}
	if(flag== 1){
		cout<<-1<<endl;
		return 0;
	}
	if(ans == 0 && n>1){
		cout<<-1<<endl;
		return 0;
	}
	cout<<ans<<endl;
	return 0;
}