ans = 0
N,M=map(int,input().split())
List=[list(map(int,input().split())) for i in range(M)]

List.sort()

for i in range(M-1):
  a = List[i][0]
  b = List[i+1][0]  
  if a == b:
    if List[i][1] != List[i+1][1]:
      ans = -1
ans3 = 0
ans2 = 0
ans1 = 0
      
for i in range(M):
  a = List[i][0]
  if a == 1:
    ans3 = List[i][1] * (10 ** (N-1))
  if a == 2:
    ans2 = List[i][1] * (10 ** (N-2))
    if N-2<0:
      ans = -1
  if a == 3:
    ans1 = List[i][1] * (10 ** (N-3))
    if N-3<0:
      ans = -1

if ans == -1:
  print(-1)
else:
  a = int(ans1+ans2+ans3)
  if len(list(str(a))) == N:
    print(a)
  else:
    print(-1)