n,m=map(int,input().split())
a=[]
for _ in range(m):
  s,c=input().split()
  s=int(s)-1
  a.append([s,c])
ans=-1
for i in range(pow(10,n)):
  s=str(i).zfill(n)
  flag=True
  for b in a:
    if not (s[b[0]]==b[1]):
      flag=False
  if flag and len(str(i))==n:
    ans=i
    break
print(ans)