import collections

n,m = map(int,raw_input().split(' '))
operations = [map(int, raw_input().split(' ')) for _ in range(m)]
def f(operations, n):

	res = [-1] * n

	for s,c in operations:
		s -=1
		if res[s] == -1:
			res[s] = c
		elif res[s] != c:
			return (False, res)
	
	for i in range(len(res)):
		if res[i] == -1: 
			res[i] = 0 if (i or n == 1) else 1
	
	if res[0] == 0 and n:
		return (false, res)
	return (True, res)
f,r = f(operations, n)
print ''.join(map(str,r)) if f else -1