N, M = map(int, input().split())
a = ["0"] * N
b = [False] * N
ansFlag = True

for i in range(M):
    s, c = map(int, input().split())
    if b[s-1] == True and a[s-1] != str(c):
        ansFlag = False

    if s == 1 and c == 0 and N > 1:
        ansFlag = False

    if b[s-1] == False:
        b[s-1] = True
        a[s-1] = str(c)

if ansFlag and int("".join(a)) >= 10**N:
    print(int("".join(a)))
else:
    print(-1)

