# C問題
N,M = map(int,input().split(" "))
Num = [0]*N
check = [0]*N
flag=0
for i in range(M):
    s,c = map(int,input().split(" "))
    if s==1 and c==0 and N!=1:
        flag=1
        break
    elif check[s-1]==1 and Num[s-1]!=c:
        flag=1
        break
    else:
        Num[s-1] = c
        check[s-1]=1

if flag==1:
    print(-1)
else:
    if Num[0]==0:
        Num[0]=1
    for i in Num:
        print("{}".format(i),end="")
    print("\n",end="")