n,m= map(int,input().split())
res=[-1]*n
for _ in range(m):
    s,c = map(int,input().split())
    if res[s-1] != -1 and res[s-1] != c:
        print(-1)
        exit()
    else:
        res[s-1] = c

if res[0] == -1 and n != 1:
    res[0] = 1
res.reverse()
out = 0
for i in range(len(res)):
    if res[i]!=-1:
        out += res[i]*10**i
    

print(out)