N,M = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(M)]
ans = [-1] * N

for i in range(M):
    if ans[sc[i][0]-1] == -1:
        ans[sc[i][0]-1] = sc[i][1]
    else:
        if ans[sc[i][0]-1] != sc[i][1]:
            print(-1)
            exit()

if ans[0] == 0:
    print(-1)
    exit()

if ans[0] == -1 and M == 0:
    ans[0] = 0
elif ans[0] == -1:
    ans[0] = 1

for i in range(N):
    if ans[i] == -1:
        ans[i] = 0

ans_str = ""
for i in range(N):
    ans_str += str(ans[i])

print(int(ans_str))