def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
N,M=MI()
S=[0]*N
for i in range(M):
  s,c=MI()
  s-=1
  if s==0 and c==0 and N!=0:
    print(-1)
    exit()
  if S[s]!=0:
    if S[s]!=c:
      print(-1)
      exit()
  S[s]=c
ans=''.join(map(str,S))
print(int(ans))