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