N, M = map(int,input().split())
SC = [list(map(int,input().split())) for o in range(M)]
ans = ["None"]*N
answer = ""
flag = 0   #存在するかどうかのフラグ 0ならあり　1ならなし

for p in range(M):
    if ans[SC[p][0]-1] == "None":   #Noneに数字を埋め込んでいく
        ans[SC[p][0]-1] = str(SC[p][1])
    
    elif ans[SC[p][0]-1] != str(SC[p][1]):  #同じ桁の数字が違う場合はアウト
        flag = 1
        break
    
    if SC[p][0] == 1 and SC[p][1] == 0:     #一番位の高い数字が０の時もアウト
        flag = 1
        break

for q in range(N):
    if ans[q] == "None":
        if q == 0:
            ans[q] = "1"
        else:
            ans[q] = "0"
    answer += ans[q]


if flag == 0:
    print(int(answer))
else:
    print(-1)