N, M = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(M)]
ans = "0"*N
okflg = 1
for i in range(M):
    if ans[sc[i][0]-1] == "0":
        ans = list(ans)
        ans[sc[i][0]-1] = str(sc[i][1])
        ans = "".join(ans)
    else:
        if ans[sc[i][0]-1] != str(sc[i][1]):
            okflg = 0
if len(str(int(ans))) == N and okflg == 1:
    print(int(ans))
else: print(-1)