n, m = map(int, input().split())
order = []
num = [-1 for i in range(n)]
for i in range(m):
  tmp = [int(i) for i in input().split()]
  order.append(tmp)

flag = True
for od in order:
  if num[od[0]-1] == -1:
    num[od[0]-1] = od[1]
  else:
    if num[od[0]-1] != od[1]:
      flag = False

if num[0] == 0:
  flag = False
else:
  for i in range(n):
    if num[i] == -1:
      num[i] = "0"
    else:
      num[i] = str(num[i])
      
if flag:
  print("".join(num))
else:
  print(-1)
  