n, m = map(int, input().split())
digit = [[] for i in range(n)]
for i in range(m):
  s, c= map(str, input().split())
  digit[int(s)-1].append(c)

flag = True
for i in range(n):
  if len(digit[i]) > 1:
    digit[i] = list(set(digit[i]))
  if len(digit[i]) > 1:
    flag = False

if n == 3:
  if len(digit[0]) > 0:
    if digit[0][0] == "0":
      flag= False
if n == 2:
  if len(digit[0]) > 0:
    if digit[0][0] == "0":
      flag = False

      
if flag:
  ans = []
  for i in range(10**(n-1),10**n):
    tmp = 0
    count =10**(n-1)
    for j in range(len(digit)):
      if len(digit[j]) > 0:
        tmp+=count*int(digit[j][0])
      count/=10
    if i == tmp:
      ans.append(i)
  print(min(ans))
else:
  print(-1)
