s = list(map(int, input().split()))
n=s[0]
m=s[1]
ans=[0]*n
flag=0
for i in range(m):
    s = list(map(int, input().split()))
    if ans[s[0]-1] != 0 and ans[s[0]-1] != s[1]:
        flag=1
        break
    elif s[0]==1 and s[1]==0:
        flag=1
        break
    else:
        ans[s[0]-1]=s[1]

if flag==0:
    print(''.join(map(str,ans)))
else:
    print(-1)