import sys
N, M = map(int, input().split())
li = [-1] * N
for i in range(M):
    s, c = map(int, input().split())
    if li[s-1] == -1 or li[s-1] == c:
        li[s-1] = c
    else:
        print(-1)
        sys.exit()
if N == 1:
    if li[0] == -1:
        ans = 0
    else:
        ans = li[0]
elif N == 2:
    if li[0] == -1 or li[0] == 0:
        print(-1)
        sys.exit()
    else:
        if li[1] == -1:
            li[1] = 0
        ans = li[0]*10 + li[1]
else:
    if li[0] == -1 or li[0] == 0:
        print(-1)
        sys.exit()
    else:
        if li[1] == -1:
            li[1] = 0
        if li[2] == -1:
            li[2] = 0
        ans = li[0]*100 + li[1]*10 + li[2]
print(ans)