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