n,m=map(int,input().split())
A=[]
[A.append(list(map(int,input().split()))) for i in range(m)]
ans=[1]
[ans.append(0) for i in range(n-1)]
for i in range(m):
  for j in range(m):
    if A[i][0]==A[j][0] and A[i][1]!=A[j][1]:
      print(-1)
      exit()
if [1,0] in A:
  print(-1)
  exit()

for i in range(m):
  ans[A[i][0]-1]=A[i][1]
print(int("".join(map(str,ans))))