#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N, M;
	cin >> N >> M;

	if(N==0||M==0){
		cout << 0 << endl;
		return 0;
	}

	vector<int> S(M), C(M);
	for(int i=0; i<M; i++) cin >> S[i] >> C[i];

	int ans[3] = {0, 0, 0};
	bool set[3] = {false, false, false};
	ans[3-N] = 1;
	for(int i=0; i<M; i++){
		if(set[S[i]-1]&&ans[S[i]-1]!=C[i]){
			cout << -1 << endl;
			return 0;
		}
		if(S[i]-1==3-N&&C[i]==0){
			cout << -1 << endl;
			return 0;
		}
		ans[S[i]-1] = C[i];
		set[S[i]-1] = true;
	}

	cout << ans[0] << ans[1] << ans[2] << endl;

	return 0;
}
