N,M = map(int,input().split()) #Nは10進法の桁数
flag = False
ans = [0]*N
s = []
c = []
for i in range(M):
  s1,c1 = [int(i) for i in input().split()]
  s.append(s1)
  c.append(c1)
for i in range(M):
  for j in range(M):
    if s[i] == s[j] and c[i] != c[j] and j != i:
      flag = True
  if s[i] == 1 and c[i] == 0 :
    flag = True
if N == 1:
  for i in range(M):
    if s[i] == 1:
      ans[0] = c[i]
  answer = ans[0]
if N == 2:
  for i in range(M):
    if s[i] == 1:
      ans[1] = c[i]
    if s[i] == 2:
      ans[0] = c[i]
  answer = 10*ans[1] + ans[0]
if N == 3:
  for i in range(M):
    if s[i] == 1:
      ans[2] = c[i]
    if s[i] == 2:
      ans[0] = c[i]
    if s[i] == 3:
      ans[0] = c[i]
  answer = 100*ans[2] +10*ans[1] + ans[0]
if flag == False:
  print(answer)
else:
  print(-1)