import sys
input = sys.stdin.readline

(n, m), s = map(int, input().split()), [0, 0, 0]
for i in range(m):
	a, b = map(int, input().split())
	if s[a-1] not in [b, 0]: print(-1); exit()
	s[a-1] = b
if s[n-1] == 0: print(-1); exit()
print(''.join(str(i) for i in s))