N, M = map(int, input().split())

num = [0]*N

for i in range(M):
    s, c = map(int, input().split())
    if N == 1:
        if c == 0:
            continue

    if num[s-1] != 0:
        if num[s-1] != c:
            print("-1")
            exit()

    elif s == 1:
        if c == 0:
            print("-1")
            exit()

    num[s-1] = c

ans = ""

if num[0] == 0:
    num[0] = 1

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


print(ans)
