#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)
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T> T in(){T x;cin>>x;return x;}
// long long a = in<long long>();
template<class T> vector<T> inarr(int s,int e, T init){
	vector<T> v;T x;
	for(int i=0;i<s;++i)v.push_back(init);
	for(int i=s;i<e;++i){cin>>x;v.push_back(x);}
	return v;
}
// vi P = inarr<int>(0,N,0);
// vi P = inarr<int>(1,N+1,INT_MAX);
// vs P = inarr<string>(0,N,"");
template<class T>void outarr(int s,int e,vector<T> &V){
	for(int i=s;i<e;i++)cout<<V[i]<<(i<e-1?" ":"\n");
}
// outarr<int>(0,V.size(),V);

int N,M;
vi S,C;

auto solve(){

	// cout<<N<<" "<<M<<"\n";//
	// outarr<int>(0,S.size(),S);///
	// outarr<int>(0,C.size(),C);///

	// vi A(N,0);
	string A;
	rp(i,0,N) A+="-";
	// cout<<A<<"\n";;//
	rp(i,0,M){
		// cout<<S[i]-1<<" "<<A[S[i]-1]<<" "<<char(C[i]+'0')<<"\n";//
		if(A[S[i]-1] == '-' || A[S[i]-1] == C[i]+'0'){
			A[S[i]-1] = C[i]+'0';
		}
		else{
			return -1;
		}
	}

	// cout<<A<<"\n";;//

	int ans = 0;
	bool zero = false;
	bool nonzero = false;
	rp(i,0,N){
		if(zero && !nonzero){
			return -1;
		}
		if(A[i]=='0') zero = true;
		if(A[i]!='0') nonzero = true;
		int a = A[i]=='-'? 0: A[i]-'0';
		ans *= 10;
		ans += a;
	}
	return ans;
}

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