import sys
(N, M) = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(M)]

answer_arry = ['x'] * N

dict = {}
for i in range(M):
    if S[i][0] in dict and S[i][1] != dict[S[i][0]]:
          print(-1)
          sys.exit()
    if S[i][0] == 1 and S[i][1] == 0:
          print(-1)
          sys.exit()
    dict[S[i][0]] = S[i][1]
    answer_arry[S[i][0] - 1] = S[i][1]

answer_str = ""
for i in range(N):
    if answer_arry[i] == 'x':
        if i == 0:
            answer_str += '1'
        else:
            answer_str += '0'
    else:
        answer_str += str(answer_arry[i])
print(int(answer_str))