n, m = map(int, input().split())

dic = [set() for _ in range(n)]

#print(dic)

for i in range(m) :
    s, c = map(int, input().split())
    dic[s-1].add(c)
#print(dic, list(dic[0])[0])
#print(dic)
for i in range(len(dic)) :
    if len(dic[i]) > 1 :
        print(-1)
        exit()
    if len(dic[i]) == 1 and i == 0:
        if list(dic[i])[0] == 0 :
            print(-1)
            exit()
    if len(dic[i]) == 0 :
        if i == 0 :
            dic[i].add(1)
        else :
            dic[i].add(0)

ans = 0
mul = 10 ** (n-1)

for i in range(len(dic)) :
    ans += (list(dic[i])[0] * mul)
    mul /= 10

print(int(ans))
