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

for i in range(M):
    s, c = map(int, input().split())
    s -= 1
    
    if A[s] != float('inf') and A[s] != c:
        print(-1)
        exit()

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

for i in range(1, N):
    if A[i] == float('inf'):
        A[i] = '0'
    A[i] = str(A[i]) 

#print(A)

if A[0] == float('inf'):
    A[0] = '1'
else:
    A[0] = str(A[0])

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

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