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

using namespace std;

signed main (){
	int n,m;
	cin >> n>> m;
	vector<pair<int,int>> A(m);
	int max = -1;
	for(int i=0;i<m;i++){
		cin >> A.at(i).first >> A.at(i).second;
		if(A[i].first > max){
			max = A[i].first;
		}
	}
	vector<int> B(max,-1);
	for(int i=0;i<m;i++){
		int p=A[i].first-1;
		if(B[p]==-1){
			B[p]=A[i].second;
		}else if(B[p] != A[i].second){
			cout<<-1<<endl;
			return 0;
		}
	}
	reverse(B.begin(),B.end());
	int ans;
	int deg = 1;
	for(int i=0;i<max;i++){
		if(B[i]==-1){
			B[i]=0;
		}
	}
	for(int i=0;i<max;i++){
		ans += B[i] * deg;
		deg *= 10;
	}
	if(ans==0){
		cout<<-1<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}