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

import numpy as np
SC=np.array(SC)


keta=np.unique(SC[:,0])
flag=0
for i in keta:
    if len(np.unique(SC[SC[:,0]==i]))>=3:
        flag=1
for x in SC[SC[:,0]==1]:
    if x[1]==0:
        flag=1

ans=[0]*N
ans[0]=1
if flag!=1:
    for i in keta:
        ans[i-1]=np.unique(SC[SC[:,0]==i])[1]
    ans2=""
    for a in ans:
        ans2+=str(a)
    print(ans2)
else:
    print(-1)