n,m=map(int,input().split())
SC=[list(map(int,input().split())) for _ in range(m)]
for ans in range(10**n+1):
  if len(str(ans))==n and all(str(SC[i][1])==str(ans)[SC[i][0]-1] for i in range(m)):
    print(ans)
    break
else:
  print(-1)