n,m = map(int,input().split())
ans = ['0']*n
check = ['']*n

for i in range(m):
	s,c = input().split()
	s = int(s)
	if check[s-1] == '':
		ans[s-1] = c
		check[s-1] = '*'
	else:
		if ans[s-1] == c:
			continue
		else:
			check[s-1] = 'NG'

if 'NG' in check:
	ans = ['-1']
if n != 1:
	if ans[0] == '0':
		ans = ['-1']


print(''.join(ans))