n, m = map(int, input().split())
if m == 0:
    print(10 ** (n - 1))
else:
    sc = {i + 1: set() for i in range(n)}
    for i in range(m):
        s, c = map(int, input().split())
        if [s, c] == [1, 0]:
            print(-1)
            break
        else:
            sc[s] |= set([c])
    else:
        flag = True
        for i in sc.values():
            if len(i) >= 2:
                flag = False
                break
        if flag == False:
            print(-1)
        else:
            ans = ["0"] * n
            for i, j in sc.items():
                if len(j) == 1:
                    for k in j:
                        ans[i - 1] = str(k)
            if ans[0] == "0":
                ans[0] = "1"
            print(int("".join(ans)))