#include <bits/stdc++.h>

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli n,m;cin>>n>>m;
	lli s[m]; char c[m];
	REP(i,0,m)cin>>s[i]>>c[i]; s[i]--;

	REP(i,0,1000){
		string A = to_string(i);
		if(A.size()!=n)continue;
		bool ok = true;
		REP(i,0,m)if(A[s[i]] != c[i])ok = false;
		if(ok){cout<<i<<endl;return 0;}
	}
	cout<<-1<<endl;


	return 0;
}