#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(){

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

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

	string A = T;
	rp(i,0,N) if(A[i]=='-') A[i] = '0';

	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;
}
