n,m = map(int,input().split())
S = []
C = []
for i in range(m):
  s,c = map(int,input().split())
  S.append(s)
  C.append(c)
ans =[0]*n
dic =[0]*n
if 1 in S :
  if C[S.index(1)] == 0:
    print(-1)
    exit()

for i in range(m):
  if dic[S[i]-1] == 0:
    ans[S[i]-1] = C[i]
    dic[S[i]-1] +=1
  elif ans[S[i]-1] !=C[i]:
    print(-1)
    exit()
result = max(1,ans[0])*10**(n-1)
for i in range(1,n):
  result += ans[i]*10**(n-1-i)
print(result)