import sys
n,m=map(int,input().split())
l=[]
for i in range(m):
    l.append(list(map(int,input().split())))
sortfirst=lambda val:val[0]
l.sort(key=sortfirst)
for i in range(m-1):
    if l[i][0]==l[i+1][0] and l[i][1]!=l[i+1][1]:
        print(-1)
        sys.exit()
if l[0]==[1,0] and n>=2:
    print(-1)
    sys.exit()
ans=[0]*n
for i in range(m):
    ans[l[i][0]-1]=l[i][1]
print("".join(map(str,ans)))
