N,M = list(map(int,input().split()))
"""
N=1 0~9
N=2 10~99
N=3 100~999
N   10**(N-1)~10**N-1
"""
S = []
C = []
for i in range(M):
    s,c = list(map(int,input().split()))
    S.append(s)
    C.append(c)

# print(S)
# print(C)

y = 10**N
for i in range(10**(N-1),10**N):
    f = True
    # print(i)
    for j in range(M):
        if str(i)[S[j]-1] != str(C[j]):
            f = False
            # print("False")
            break
    if f:
        y = min(y,i)
        
if y == 10**N:
    y = -1

print(y)