#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)
int N,M;
vi S,C;

auto solve(){
	int top = 3 - N;

	string T(3,'-');
	rp(i,0,M) T[top + S[i]-1] = C[i]+'0';

	// ote(top);ote(T);//

	rp(i,0,M) if(T[S[i]-1] != C[i]+'0') return -1;
	if(N>1 && T[top]=='0') return -1;

	string A=T;
	if(N>1 && T[top]=='-' && T[top+1]!='-') A[top] = T[top+1]=='0'? '1':'0';
	// if(N>1 && T[top]=='-' && T[top+1]!='-') A[top] = T[top+1]=='0'? '1':'0';
	if(A[0]=='-') A[0] = '0';
	if(A[1]=='-') A[1] = '0';
	if(A[2]=='-') A[2] = '0';

	// ote(A);//
	return stoi(A);
}

int main(){
	cin>>N>>M;
	S.resize(M);
	C.resize(M);
	rp(i,0,M) cin>>S[i]>>C[i];
	cout<< solve() <<endl;
}
