#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define rep0(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define re return
#define mp map<int,int>
#define N 200005
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
using namespace std;
int s[N],c[N],n,m;
int main() {
	cin>>n>>m;
	rep0(i,0,m) cin>>s[i]>>c[i];
	rep0(i,0,4005){
		bool pd=1;
		string ch=string(i);
		if(ch.size()!=n) break;
		rep0(j,0,m){
			if(ch[s[j]-1]!=c[j]+'0')pd=0;
		}
		if(pd){
			cout<<i;
			re 0;
		}
	}
	cout<<-1;
	re 0;
}
