SC=[]
N,M = map(int,input().split())
import sys
for _ in range(M):
    SC.append(list(map(int,input().split())))

ans=[[0] for i in range(N)]
for value in SC:
    ans[value[0]-1].append(value[1])
#print(ans)
keta=10**(N-1)
answ=0
if(keta==1):
    print(0)
    sys.exit()

for a in ans:
    tmp=a.pop(0)
    a.sort()
    #tmp=0
    while(a!=[] and tmp==0):
        tmp=a.pop(0)
    answ+=tmp*keta
    keta=keta//10

print(answ) if(len(str(answ))==N) else print(-1)

