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

    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)

    if M == 0:
        return small

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

    return -1

print(a())


