N,M=map(int,input().split())
d=[-1 for _ in range(N)]
for m in range(M):
  s,c=map(int,input().split())
  if d[s-1]==-1:
    d[s-1]=c
  elif d[s-1]!=c:
    print(-1)
    exit()

if N>1 and d[0]==0:
  print(-1)
  exit()

A=0
for i in range(N):
  A=A*10+(d[i] if d[i]!=-1 else 0)

print(A)
