n,m = map(int,input().split())
d = dict()
for i in range(m):
    k,v = map(int,input().split())
    if v<0:
        print(-1)
        exit()
    if k in d:
        if d[k] !=v:
            print(-1)
            exit()
    else:
        d[k] = v
res = ""
for i in range(1,n+1):
    if i not in d:
        d[i] = 0
    res += str(d[i])
res = int(res)
if n !=1:
    if res == 0:
        print(-1)
        exit()
print(res)