n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]

ans=[-1 for i in range (n)]
fail=0

for i in range(m):
    ss=sc[i][0]
    cc=sc[i][1]
    aa=ans[ss-1]
    if aa==-1:
        ans[ss-1]=cc
    elif aa!=cc:
        fail=-1

if n>1 and ans[0]==0:
    fail=-1

answer=0

for i in range (n):
    if ans[i]==-1:
        ans[i]=0
    answer*=10
    answer+=ans[i]

if fail==-1:
    print(-1)
else:
    print(answer)
    