N,M = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(M)]
three = 1000
two = 100
one = 10
for i in range(M):
  if sc[i][0]== 1:
    three = min(10**(N-1)*sc[i][1],three)
  elif sc[i][0]== 2:
    two = min((10**N)/100*sc[i][1],two)
  elif sc[i][0]== 3:
    one = min(sc[i][1],one)
if N == 3 and three == 1000 or three == 0:
  print(-1)
  exit()
if two == 100 or two == 0:
  two = 0
  if N <= 2:
    print(-1)
    exit()
if one == 10 or one == 0:
  one = 0
  if N == 1:
    print(-1)
    exit()
print(three+two+one)