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

S = [0]*N
for x in range(M):
    s, c = list(map(int,input().split()))
    if c > S[s-1]:
        S[s-1] = c

ans = ""
for x in range(M):
    ans += str(S[x])

ans = int(ans)

if len(str(ans)) == N:
    print(int(ans))
else:
    print(-1)