N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]
dict = {}

if M == 0 :
    print(10**(N-1))
    exit()

for x in L :
    dict.setdefault(x[0],[])
    dict[x[0]].append(x[1])

for k,v in dict.items():
    dict[k] = set(v)

isFirstZero = 2 <= N and (1 in dict and dict[1] == {0})
isOverlapping = all([ 2 <= len(i) for i in dict.values()])

if isFirstZero or isOverlapping :
    print(-1)
else :
    ans = 0
    for k,v in dict.items() :
        ans += list(v)[0] * 10**(N-k)
    print(ans)