#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define rep(N) for(int i=0;i<N;i++)
#define rep2(N1,N2) for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)
#define rep3(N1,N2,N3)for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)for(int k=0;k<N3;k++)
#define For(i,N) for(int i=0;i<N;i++)
void yn(bool b) {
	if (b)printf("yes\n");
	else printf("no\n");
}

void Yn(bool b) {
	if (b)printf("Yes\n");
	else printf("No\n");
}

void YN(bool b) {
	if (b)printf("YES\n");
	else printf("NO\n");
}

int main(){
	int N, M;
	cin >> N >> M;
	vector<int>s(M);
	vector<int>c(M);
	rep(M)
		cin >> s[i] >> c[i];
	vector<int>num(N,-1);
	int ans = 0;
	rep(M) {
		if (num[s[i]-1] != -1 && num[s[i]-1] != c[i]) {
			ans = -1;
			break;
		}
		else
			num[s[i]-1] = c[i];
	}
	if (ans == 0) {
		if (num[0] == -1)
			num[0] = 1;
		rep(N) {
			if (num[i] == -1)
				num[i] = 0;
		}
		rep(N) {
			ans = ans + pow(10, N - 1-i)*num[i];
		}
	}
	if (N > 1 && num[0] == 0)
		ans = -1;
	cout << ans;

}