// C - Guess The Number
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	int N,M; cin>>N>>M;
	int S[M]; char C[M];
	rep(i,M){ cin>>S[i]>>C[i]; --S[i]; }
	rep(i,1000){
		string A = to_string(i);
		if(A.size() != N) continue;
		bool ok = true;
		rep(j,M) if(A[S[j]] != C[j]){ ok = false; break; }
		if(ok){ cout<<i<<endl; return 0; }
	}
	puts("-1");
}