#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n, m, l[10] = {0}, r[10] = {0};
	scanf("%d%d", &n, &m);
	for(int i = 0; i < m; i++)
		scanf("%d%d", &l[i], &r[i]);
	int ret[4];
	memset(ret, -1, sizeof(ret));
	int flag = 1;
	for(int i = 0; i < m; i++)
	{
		if(ret[l[i]] < 0 || ret[l[i]] == r[i]) ret[l[i]] = r[i];
		else{
			flag = 0;break;
		}
	}
	if(flag)
	{
		if(n == 1){
			if(ret[1] == -1) ret[1] = 0;
			printf("%d\n", ret[1]);
		}else if(n == 2){
			if(ret[1] > 0){
				if(ret[2] == -1) ret[2] = 0;
				printf("%d%d\n", ret[1], ret[2]);
			}
			else printf("-1\n");
		}else{
			if(ret[1] > 0){
				if(ret[2] == -1) ret[2] = 0;
				if(ret[3] == -1) ret[3] = 0;
				printf("%d%d%d\n", ret[1], ret[2], ret[3]);
			}else printf("-1\n");
		}
	}else printf("-1\n");
	
	return 0;
} 