def a():
    N,M = map(int,input().split())

    S = [0]*M
    C = [0]*M
    d = dict()
    for _ in range(M):
        S[_],C[_] = map(int,input().split())
        S[_] -= 1
        if (S[_] in d)and(d[S[_]] != C[_]):
            return -1
        else:
            d[S[_]] = C[_]

    small = 0
    if N != 1:
        small = int("1"*N)
    large = int("9"*N)

    for i in range(small,large+1):
        i = str(i)
        a = True
        for k,v in d.items():
            a = a and (int(i[k]) == v)
        if a:
            return i

    return -1

print(a())


