n,m=map(int,input().split())
fig=[0 for _ in range(n)]
fig[0]=1
f=[0 for _ in range(n)]

for i in range(m):
  s,c=map(int,input().split())
  if f[s-1]==1 and fig[s-1]!=c:
    print(-1)
    exit()
  else:
    f[s-1]=1
    fig[s-1]=c
if fig[0]==0:
  print(-1)
  exit()
ans=0
for i in range(n):
  ans+=fig[i]*(10**(n-i-1))





print(ans)