N,M = map(int,input().split())
SC = []
for _ in range(M):
    SC.append([int(i) for i in input().split()])
ans = [""]*N
flg = True
for sc in SC:
    if ans[sc[0]-1] == "" or ans[sc[0]-1] == sc[1]:
        ans[sc[0]-1] = sc[1]
    else:
        flg = False
if flg == False or ans[0] == 0:
    print(-1)
else:
    ans_str = [0 if a=="" else a for a in ans]
    print(*ans_str,sep="")
    