# C - Guess The Number

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

mi = 0
if N > 0:
    mi = 10**(N-1) 

ans = -1
for i in range(mi, 10**N):
    for m in range(M):
        if str(i)[S[m]-1]!=str(C[m]):
            break
    else:
        ans = i
        break

print(ans)
