n,m = list(map(int, input().split()))
l=[list(map(int, input().split())) for _ in range(m)]
ans=['']*n
for s,c in l:
    i=s-1
    if not ans[i]:
        ans[i]=str(c)
    elif ans[i]!=str(c):
        print(-1)
        exit()

if n>1 and ans[0]=='0':
    print(-1)
    exit()

ans=''.join([i if i else '0' for i in ans])
if n>1 and ans[0]=='0':
    ans='1'.join(ans[1:])

print(ans)