n,m = map(int, input().split())
x = []
y = []
for i in range(m):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
#print(n,m,x,y)

#print(len(set(x)), len(set(y)))

if n==1:
  ans = '0'
elif n==2:
  ans = '10'
else:
  ans = '100'

for i in range(m):
  if n != 1 and y[i] == 0:
    ans = '-1'
    break
  elif len(set(x)) != len(set(y)):
    ans = '-1'
    break
  else:
    s = list(ans)
    s[x[i]-1] = str(y[i])
    ans = "".join(s)
print(ans)
  
  