N, M = map(int, input().split())
list_n = [0, 0, 0]
bool_list = [False, False, False]
ans = ""
flag = 0
for m in range(M):
    s, c = map(int, input().split())
    if (bool_list[s-1] == False) | ((bool_list[s-1] == True) & (list_n[s-1]==c) ):
        list_n[s-1]=c
        bool_list[s-1]=True
    else:
        ans = "-1"
        flag = 1
        break
if flag == 0:
    for i, b in enumerate(bool_list):
        if b:
            ans += str(list_n[i])
        elif (b==False) & (i != 0):
            ans += "0"

ans = int(ans)
        
print(ans)