N,M=map(int,input().split())
A=[list(map(int,input().split())) for i in range(M)]
if N==1:
  e,f=0,10
elif N==2:
  e,f=10,100
else:
  e,f=100,1000
for i in range(e,f):
  a=str(i)
  flag=True
  for j,k in A:
    if a[j-1]!=str(k):
      flag=False
  if flag:
    print(a)      
    exit()
print(-1)  