a,b=map(int, input().split())
s = [list(map(int, input().split())) for i in range(b)]
s = sum(s, [])
L =[0]*a
ans = 0
ab = 10**a

for i in range(b):
    if L[s[i*2]-1] == 0:
        L[s[i*2]-1] = s[i*2+1]
    if L[s[i*2]-1] != 0 and L[s[i*2]-1] == s[i*2+1]:
        pass
    if L[s[i*2]-1] != 0 and L[s[i*2]-1] != s[i*2+1]:
        ans += 1

if ans == 0:
    if b == 0:
        print(ab)
    if b !=0 and L[0] == 0:
        print('-1')
    if b !=0 and L[0] != 0:
        T = ''.join(map(str,L))
        print(T)
if ans != 0:
    print('-1')