N,M=map(int,input().split())
INF=float("inf")
num=[INF]*N
ans=""
for i in range(M):
    s,c=map(int,input().split())
    if s==1 and c==0:
        print(-1);exit()
    if num[s-1]==INF or num[s-1]==c:
        num[s-1]=c
    else:
        print(-1);exit()
for k in range(1,N):
    if num[k]==INF:
        num[k]=0
if num[0]==INF:
    num[0]=1
for k in range(N):
    ans+=str(num[k])
print(ans)
