def solve():
    cmd = []
    n, m = map(int, input().split())
    for _ in range(m):
        cmd.append(tuple(map(int, input().split())))

    res = ["0"] * n
    res[0] = "1"
    cmd.sort()

    for i in range(len(cmd)-1):
        t1, t2 = cmd[i], cmd[i+1]
        if t1[0] == t2[0] and t1[1] != t2[1]:
            print(-1)
            return

    for si, ci in cmd:
        res[si-1] = str(ci)

    r = int("".join(res))

    if len(str(r)) == n:
        print(r)
    else:
        print(-1)

solve()