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