#C
#入力
N,M=map(int,input().split())
T=[list(map(int,input().split())) for i in range(M)]
#処理
A=[0 for i in range(N+1)]#桁格納
B=[0 for i in range(N+1)]#処理済みフラグ

t=0
for i in T:
    if B[i[0]]==1:#処理済み
        if A[i[0]]!=i[1]:#前と違う
            print(-1)
            t=1
            break
        
    else:
        A[i[0]]=i[1]
        B[i[0]]=1#処理済み

if A[1]==0 and B[1]==1:
    print(-1)
    t=1
if t==0:
    x=0
    for j in range(1,N+1):
        if B[j]==1:
            x+=A[j]*(10**(N-j))
        else:
            if j==1:
                x+=10**(N-j)
    print(x)
