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

r="000"
r = list(r)

k ={}
for _ in range(m):
    x,y = map(int,input().split())

    if n > 1 and x == 1 and y == 0: print('-1');exit()

    if k.get(x) and k[x] != str(y): print('-1');exit()
    else: k[x] = str(y)

for i,j in k.items():
    r[i-1] = j

print(int(''.join(r)))
