N, M = map(int, input().split())
N_str = str(N)
flag = 1
kettei = [-1 for i in range(N)]
for i in range(M):
  s, c = map(int, input().split())
  if kettei[s-1] == -1:
    kettei[s-1] = c
  elif kettei[s-1] != c:
    flag = 0
if kettei[0] == 0 :
  flag = 0
    
ans = ""

for i in range(N):
  if kettei[i] == -1:
    ans += "1"
  else:
    ans += kettei[i]
if flag:
  print(ans)
else:
  print(-1)