n,m=map(int,input().split())
s=[]
t=[]
for i in range(m):
  u,v=input().split()
  s.append(int(u)-1)
  t.append(v)
ans=-1
for i in range(1000):
  x=str(i)
  if len(x)!=n:
    continue
  flag=True
  for j in range(m):
    if x[s[j]] != t[j]:
      flag = False
  if flag:
    ans=i
    break
print(ans)