n,m=map(int,input().split())

flag=[False]*n
result=[0]*n
result[0]=1

temp=[]
for _ in range(m):
    l=list(map(int,input().split()))
    temp.append(l)

res_flag=0

for i in range(len(temp)):
    if temp[i][0]==1 and temp[i][1]==0:
        print("-1")
        res_flag=1
        break
    else:
        if flag[temp[i][0]-1]==True and result[temp[i][0]-1] != temp[i][1]:
            print("-1")
            res_flag=1
            break
        else:
            result[temp[i][0]-1]=temp[i][1]
            flag[temp[i][0]-1]=True

f_res=map(str,result)
if res_flag==0:
    print("".join(f_res))