N, M = map(int, input().split())
A = [10 for _ in range(N)]

for i in range(M):
    s, c = map(int, input().split())
    s -= 1

    A[s] = min(A[s], c)

for i in range(N):
    if A[i] == 10:
        A[i] = 0
    A[i] = str(A[i]) 

print(A)
ans = int(''.join(A))

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