n, m = map(int, input().split())
array = []
for i in range(m):
  alist = list(map(int, input().split()))
  array.append(alist)

flg = True
num = [0]*n

for i in range(m):
  if num[array[i][0]-1] == 0:
    num[array[i][0]-1] = array[i][1]
  else:
    if num[array[i][0]-1] != array[i][1]:
      flg = False
      break

if flg == True and num[0] != 0:
  num2 = 0
  for i in range(n):
    num2  = num2 + num[i] * (10**(n-i-1))
  print(num2)
else:
  print(-1)
  