N,M=map(int,input().split())
sc=[list(map(int,input().split()))for _ in [0]*M]

ans=['1']+['0']*(N-1)
count=[0]*N
for s,c in sc:
    if count[s-1]==1 and ans[s-1]!=str(c):
        ans='-1'
        break
    else:
        ans[s-1]=str(c)
        count[s-1]=1

if N>=2 and ans[0]=='0':
    ans='-1'

if M==0:
    ans='0'

print(''.join(ans))