N,M=map(int,input().split())
S=[list(map(int,input().split())) for i in range(M)]

A=[1]
for i in range(1,N):
    A.append(0)

a=False
for i in range(M):
    if a==False:
        for j in range(M):
            if S[i][0]==S[j][0] and S[i][1]!=S[j][1]:
                print(-1)
                a=True
                break

if a==False:
    for i in range(M):
        A[S[i][0]-1]=S[i][1]
    if A[0]!=0:
        B=list(map(str,A))
        print("".join(B))
    else:
        print(-1)