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 s == 0 and c == 0 and N > 1:
        continue        
    A[s] = min(A[s], c)
    #A[s] = c

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

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

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