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

X = [0] * N
R = [0] *  N

ans = True
for i in range(M):
    s,c = map(int,input().split())
    
        
    if R[s-1] == 0:
        X[s-1] = c
        R[s-1] = "T"
        
    elif R[s-1] == "T" and X[s-1] != c or (s == 1 and c == 0):
        ans = False
        break
        
if ans:
    if X[0] == 0:
            cnt = 1
    else:
        cnt = X[0]
    for i in range(1,N):
        cnt = cnt * 10 + X[i]
        
    print(cnt)

else:
    print(-1)