# C - Guess The Number
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]

ans = [0,0,0]

for i in range(M):
    for j in range(i+1,M):
        if (SC[i][0] == SC[j][0]) and (SC[i][1] != SC[j][1]):
            print(-1)
            quit()

for k in range(M):
    ans[SC[k][0]-1] = SC[k][1]

ans = [str(ans[i]) for i in range(3)]

res = "".join(ans)
res = res[(3-N):4]

if res[0] == "0":
    ref = list(res)
    ref[0] = "1"
    res = "".join(ref)

print(res)
