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')

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()
for i in range(M):
  ans[sc[i,0]-1] = sc[i,1]
if ans[0] == 0:
  print(-1)
  sys.exit()
elif ans[1] == 0:
  print(-1)
  sys.exit()

if ans[2]==-1:
  ans[2] = 1
if ans[1]==-1:
  ans[1] = 0
if ans[0]==-1:
  ans[0] = 0

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