N,M=map(int,input().split())
res=[0]*(N)
ans=[0]*(N)
for i in range(M):
    si,ci=map(int,input().split())
    si-=1
    if res[si]==1 and ans[si]!=ci:
        print(-1)
        exit()
    res[si]=1
    ans[si]=ci
if N==1:
    if ans==[0]:
        print(0)
        exit()
    else:
        print(ans[0])
        exit()
if ans[0]==0:
    print(-1)
    exit()

ans = map(str,ans)
print(''.join(ans))