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

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

Z = [[] for i in range(M)]
for j in range(M):
    for i in range(10**(N-1)+1, 10**N):
        if S[j] > N : 
            break
        i = str(i)
        if i[S[j]-1] == str(C[j]):
            Z[j].append(int(i))

ZZ = Z[0]
for j in range(1, M):
    set_zz = set(ZZ)
    set_z = set(Z[j])
    ZZ = set_zz & set_z

try:
    print(min(ZZ))
except:
    print(-1)