n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]

flag=[-1]*n

if [1,0] in l:
  print(-1)
  exit()

for x in l:
  s,c=x
  if flag[s-1]!=-1 and flag[s-1]!=c:
    print(-1)
    exit()
  flag[s-1]=c

ans=0
tmp=[]
for x in l:
  s,c=x
  if not s in tmp:
    tmp.append(s)
    ans+=c*10**(n-s)
if ans<10**(n-1):
  ans+=10**(n-1)
print(ans)