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:
  if three == 1000:
    three = 1
  elif three == 0:
    print(-1)
    exit()
elif N == 2:
  if two == 100:
    two = 1
  elif two == 0:
    print(-1)
    exit()
elif N == 1:
  if one == 10:
    one = 1
  elif one == 0:
    print(-1)
    exit()
print(three+two+one)