n,m = map(int, input().split())
lists = [0,0,0]
error = 0
for i in range(m):
  a, b = map(int, input().split())
  if (lists[a-1] == 0) or (lists[a-1] == b):
    lists[a-1] = b
  else:
    error += 1
if (len(lists) != 1) and (lists[0] == 0):
  error += 1
result = 0
if error == 0:
  for i in range(n):
    result += lists[i] * 10**(n-i-1)
else:
  result = -1
print(result)