N, M = [int(x) for x in input().split()]

S = []
for i in range(N):
    S.append(None)

for i in range(M):
    s, c = [int(x) for x in input().split()]
    
    if S[s - 1] == None:
        S[s - 1] = c
    elif S[s - 1] == c:
        pass
    else:
        S[0] = -1
        break

if S[0] == 0 and N == 1:
    print(0)
elif S[0] == -1:
    print(-1)
else:
    for s in S:
        if s == None:
            s = '0'
        print(s, end="")
    print()