#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,M; cin>>N>>M;
	string ret=string(N,'0');
	vector<int> s(M);
	vector<char> c(M);
	for (int i=0; i<M; i++)
		cin>>s[i]>>c[i], ret[s[i]-1]=c[i];
	for (char ch='1'; ch<='9'; ch++) {
		ret[0]=ch;
		bool ok=true;
		for (int i=0; i<M; i++)
			if(ret[s[i]-1]!=c[i])
				ok=false;
		if(ok) {
			cout<<ret<<"\n";
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}