def No():
    print("-1")
    exit()

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

# print(N+M)
    
S = []
C = []
Flag = True

for i in range(0,M):
    s,c = map(int, input().split(" "))
    for j in range(0, len(S)):
        if s == S[j] and c != C[j]:
            Flag = False
    S.append(s)
    C.append(c)

if Flag is False:
    No()
output = 0
flag = [False,False,False]
print(S)
print(C)
# if S.count(1) == 0:
#     print(S.count(1))
#     No()

for i in range(0,len(S)):
    
    if S[i] == 1 and flag[0]==False:
        if C[i] == 0 and N != 1:
            No()
        output += 100 * C[i]
        flag[0]=True
        
    if S[i] == 2 and flag[1]==False:
        output += 10 * C[i]
        flag[1]=True
        
    if S[i] == 3 and flag[2] == False:
        output += C[i]
        flag[2]=True
        
if (N == 3 or N == 2) and flag[0]==False:
    output += 100

output = int(output / (10 ** (3-N)))
# print(output)
if output < 10 ** (N-1) and output != 0:
    No()
print(output)