#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
using LLint = long long int;

const int mod = 1000000007;
int main(){
	int N,M;
	int S[6];
	int C[6];
	cin>>N>>M;
	for(int i=0;i<M;++i) cin>>S[i]>>C[i];
	
	map<int,int> mp;
	mp[1]=0;
	N==2?mp[2]=1:mp[2]=0;
	N==3?mp[3]=1:mp[3]=0;
	
	bool check=true;
	for(int i=0;i<M;++i)
	{
		for(int j=i+1;j<M;++j)
		{
			if(S[i]==S[j]&&C[i]!=C[j])
			{
				check=false;
				break;
			}
		}
		mp[N-S[i]+1]=C[i];
	}
	if(mp[N]==0&&N!=1)check=false;
	int ans=100*mp[3]+10*mp[2]+mp[1];
	check?cout<<ans<<endl:cout<<-1<<endl;
	return 0;
}
