N, M = map(int, input().split())
sc_list = []
for i in range(M):
    s, c = map(int, input().split())
    sc_list.append([s,c])
ans = ""
flag = 0
num_slot = [-1 for i in range(N)]
for lists in sc_list:
    if num_slot[lists[0]-1] != -1 and num_slot[lists[0]-1] != lists[1]:
        print(-1)
        flag = 1
        break
    else:
        num_slot[lists[0]-1] = lists[1]
if flag == 0:
    for i in range(N):
        if num_slot[i] != -1:
            ans += str(num_slot[i])
        else:
            if i == 0:
                ans += "1"
            else:
                ans += "0"
    if ans[0] == "0" and ans != "0":
        print(-1)
    else:
        print(int(ans))