import numpy as np	
import sys
stdin = open(0)
N,M = (stdin.readline()).split()
N = int(N)
M = int(M)
sc = []
ans = np.array([-1,-1,-1])
for i in range(M):
  sc.append(stdin.readline().split())
sc = np.array(sc, dtype='int')

# error input
if (N<1)|(N>3):
  print(-1)
  sys.exit()
if (M<0)|(M>5):
  print(-1)
  sys.exit()
for i in range(M):
  if(sc[i,0]>N)|(sc[i,0]<1):
    print(-1)
    sys.exit()
  if(sc[i,1]>9)|(sc[i,1]<0):
    print(-1)
    sys.exit()
  
#conflict
for i in range(M):
  for j in range(i+i,M):
    if ((sc[i,0] == sc[j,0]) & (sc[i,1] != sc[j,1])):
      print(-1)
      sys.exit()

ans = np.array([-1,-1,-1])
for i in range(M):
  ans[sc[i,0]-1] = sc[i,1]

print(ans)
if N==1:
  if(ans[0]==-1):
    answer = 0
  else:
    answer = ans[0]
  print(answer)
  sys.exit()
elif N==2:
  if(ans[0]==-1):
    ans[0]=1
  elif(ans[0]==0):
    print(-1)
    sys.exit()
  if(ans[1]==-1):
    ans[1] =0
  answer = ans[0]*10+ans[1]
  print(answer)
  sys.exit()
else:
  if(ans[0]==0):
    print(-1)
    sys.exit()
  elif(ans[0]==-1):
    ans[0] = 1
  if(ans[1]==-1):
    ans[1]=0
  if(ans[2]==-1):
    ans[2]=0
  answer = ans[0]*100+ans[1]*10+ans[2]
  print(answer)
  sys.exit()
  
