i = list(map(int, input().split()))
N=i[0]
M=i[1]
a=0
if N==1:
  J=[0]
elif N==2:
  J=[1,0]
else:
  J=[1,0,0]

C = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
  for k in range(i):
    if (C[i][0]==C[k][0]) and (C[i][1]!=C[k][1]):
      a=-1
  J[C[i][0]-1]=C[i][1]

b=0
for i in range(N):
  b=b+(J[i]*(10**(N-1-i)))

if N!=1:
  if J[1]==0:
    a=-1

if a==-1:
  print(a)
else:
  print(b)