import sys
N,M=map(int,input().split())
SC=dict()
for n in range(1,N+1):
    SC[n]=[]

for _ in range(M):
    s,c=map(int,input().split())
    if(s==1 and c==0 and N!= 1):
        continue
    SC[s].append(c)
ans = 0
for item in SC.items():
    keta=item[0]
    if(item[1] == []):
        continue
    item[1].sort()
    kazu=item[1][0]
    ans += (kazu*10**(N - keta))

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