import sys

n,m=map(int,input().split())

g=[-1]*n

for i in range(m):

  s,c=map(int,input().split())

  if g[s-1]!=-1 and g[s-1]!=c:
    print("-1")
    sys.exit()

  elif n>=2 and s==1 and c==0:
    print("-1")
    sys.exit()

  else:
    g[s-1]=c

ans=0
h=1

for i in range(m-1,-1,-1):

  if g[i]==-1:

    if n>=2 and i==0:
      g[i]=1
    else:
      g[i]=0


  ans+=int(g[i])*h
  h=h*10


print(ans)