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

sc = sorted(sc, key= lambda x: x[0])
ans = [0] * N

check = [-1] * N
for i in sc:
    if N == 3 and i[0] == 1 and i[1] == 0:
        print(-1)
        exit()
    if N == 2 and i[0] == 1 and i[1] == 0:
        print(-1)
        exit()

    if check[i[0]-1] == -1:
        check[i[0]-1] = i[1]
    elif check[i[0]-1] != i[1]:
        print(-1)
        exit()


for i in sc:
    ans[i[0] - 1] = i[1]
for i in ans:
    print(i, end="")