N,M=map(int,input().split())
A=[list(map(int,input().split())) for i in range(M)]
D=[[]for i in range(N)]
for a,b in A:
  D[a-1].append(b)
for i in range(N):
  if D[i]==[]:
    D[i].append(0)
  D[i]=list(set(D[i]))
  if len(D[i])>1:
    print(-1)
    exit()
C=[]
for i in range(N):
  C.append(D[i][0])
if C[0]==0 and N>1:
  print(-1)
  exit()
print(*C,sep='')
