n,m= map(int,input().split())
nd = {i:set() for i in range(1,n+1)}
for i in range(m):
    s,c= map(int,input().split())
    nd[s].add(c)
ns = [0]*n
for i in range(1,n+1):
    if   len(nd[i])==0:ns[i-1] = 1 if i==1 else 0
    elif len(nd[i])==1:ns[i-1] = list(nd[i])[0]
    else:
        print(-1)
        break
else:
    if ns[0]==0:
        if n==1:print(0)
        else:print(-1)
    else:print(''.join([str(t) for t in ns]))
