N,M=map(int,input().split())
num=[list(map(int,input().split())) for i in range(M)]
ans=[-1]*N
check=True
for i in range(M):
    if ans[num[i][0]-1]==-1:
        ans[num[i][0]-1]=num[i][1]
    elif ans[num[i][0]-1]!=num[i][1]:
        check=False
        break
if ans[0]==-1 and N>1:
    ans[0]=1
elif ans[0]==-1 and N==1:
    ans[0]=1
elif ans[0]==0:
    check=False
for i in range(N):
    if ans[i]==-1:
        ans[i]=0

if check==False:
    print("-1")
else:
    answer=0
    for i in range(N):
        answer+=ans[i]*(10**(N-i-1))
    print(answer)
