def solve():
    n, m = map(int, input().split())
    ans = ["0"] * (n + 1)
    SC = {}
    for _ in range(m):
        s, c = input().split()
        if s in SC:
            if SC[s] != c:
                return -1
        else:
            SC[s] = c
    for s, c in SC.items():
        ans[int(s)] = c
    if ans[1] == "0":
        if n == 1:
            return 0
        if 1 in SC and SC[1] == "0":
            return -1
        ans[1] = "1"
    return "".join(ans[1:])
print(solve())
