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

def f():
    S = {}
    for _ in range(M):
        s, c = map(int, input().split(" "))
        if S.get(s) is not None and S.get(s) != c:
            
            return -1
        S[s] = min([S.get(s, 10000), c])

    digit = max(S.keys())

    if S[digit] == 0:
        return -1

    N = []
    for i in range(digit):
        N.append(str(S.get(i + 1, 0)))

    return "".join(N)

print(f())