import sys
N,M=map(int,input().split())
S=[list(map(int,input().split())) for i in range(M)]
num=["x"]*N
numl=""
for i in range(M):
    if num[S[i][0]-1]=="x":
        num[S[i][0]-1]=str(S[i][1])
    else:
        print(-1)
        sys.exit()
for i in range(N):
    if num[i]=="x":
        num[i]="0"
for i in num:
    numl+=i
if num[0]=="0":
    print(-1)
else:
    print(int(numl))