in1 = input('')
n = int(in1.split(' ')[0])
m = int(in1.split(' ')[1])
l = []
for i in range(0,n):
  l.append(-1)

hasError = False
for i in range(0,m):
  in2 = input('')
  idx = int(in2.split(' ')[0])-1
  li = int(in2.split(' ')[1])
  if l[idx] != -1 and l[idx] != li:
    hasError = True
  else:
    l[idx] = li

for i in range(0,n):
  if l[i] == -1:
    l[i] = 0


result = 0
for i in range(0,n):
  ix = 1
  for j in range(0,(n-i-1)):
    ix*=10
  result += int(l[i])*ix

if result < 0:
  result = -1
if n == 1 and result == 0:
  result = 0
elif len(str(result)) != n:
  result = -1
if hasError == True:
  result = -1
print(result)

