N, M = map(int, input().split())

ans = ["_" for _ in range(N)]
change = []
for _ in range(M):
    s_i, c_i = map(int, input().split())
    if s_i not in change:
        ans[s_i - 1] = str(c_i)
        change.append(s_i)
    else:
        if ans[s_i - 1] == str(c_i):
            continue
        else:
            print(-1)
            exit()

new_ans = []
for i, k in enumerate(ans):
    if k == "_":
        if i == 0:
            new_ans.append("1")
        else:
            new_ans.append("0")
    else:
        new_ans.append(k)

if N > 1:
    if new_ans[0] == "0":
        print(-1)
    else:
        print("".join(new_ans))
else:
    print(new_ans[-1])