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

ans = [-1] * N

for i in range(M):
    s = sc[i][0] - 1
    c = sc[i][1]
    if ans[s] is -1:
        ans[s] = c
    elif not ans[s] == c:
        print(-1)
        exit()
a = 0
for i in range(N):
    if ans[i] is -1:
        ans[i] = 0
    a += ans[i]*10**(N-i-1)

if ans[-1] == 0:
    print(-1)
    exit()

print(a)
