N, M = map(int, input().split())
s_c = []
for _ in range(M):
    s_c.append(list(map(int, input().split())))
    
    
flag = False
num = [-1,-1,-1]
for s,c in s_c:
    if num[s-1] == -1:
        num[s-1] = c
    elif not num[s-1] == c:
        flag = True

# print(num)
ans = 0
if flag:
  print(-1)
elif len(num) >1 and num[0] == 0:
  print(-1)
else:
  for i,n in enumerate(num):
      if n == -1:
          n = 0
      else:
          ans += n*(10**(3-i))
  print(ans)
  