#include <cstdio>
using namespace std;

int main(int argc, char** argv)
{
	int n, m;
	scanf("%d%d", &n, &m);
	char res[5], temp_output = '\0';
	for(int i=0; i<n; i++) res[i] = '0';
	int lastc[5] = {-1, -1, -1, -1, -1};
	for(int i=0; i<m; i++)
	{
		int s, c;
		scanf("%d%d", &s, &c);
		if(s > n) {puts("-1"); return 0;}
		if(lastc[--s] != -1)
		{
			if(lastc[s] == c) continue;
			puts("-1");
			return 0;
		}
		if(s == 0)
		{
			if(n == 1) temp_output = c + '0';
			else if(c == 0) {puts("-1"); return 0;}
		}
		lastc[s] = c, cnt ++;
		res[s] = c + '0';
	}
	if(temp_output) {putchar(temp_output); putchar('\n'); return 0;}
	if(n == 1) {puts("0"); return 0;}
	if(res[0] == '0') res[0] = '1';
	puts(res);
	return 0;
}