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

l = [-1 for _ in range(N)]

S_C = []
for _ in range(M):
    s, c = map(int, input().split())
    S_C.append([s, c])

for s, c in S_C:
    if l[s - 1] == -1:
        l[s - 1] = c
    elif l[s - 1] != c:
        print(-1)
        quit(0)

if N > 1 and l[0] == 0:
    print(-1)
    quit(0)

ans = ''
for i in range(N):
    if l[i] == -1:
        ans += '0'
    else:
        ans += str(l[i])

print(int(ans))
