n,m =map(int,input().split())
l= [11]*n
for _ in range(m):
    s,c=map(int,input().split())
    if l[s-1] != str(c) and l[s-1] != 11:
        print(-1)
        exit()
    else:
        l[s-1] = str(c)
for index,i in enumerate(l):
    if i == 11:
        l[index] = '0'
if n>=2:
    if l[0] == '0' or l[0]==l[1]=='0':
        print(-1)
        exit()
print(''.join(l))
