S=[];C=[];s=0;c=0;f=0;T=""
N,M=map(int,input().split())
for i in range(M):
  s,c=map(int,input().split())
  S.append(s)
  C.append(c)
#print(S)
#print(C)
X=[-1]*N
#print(X)
for i in range(M):
  if X[S[i]-1]==-1:
    X[S[i]-1]=C[i]
  elif X[S[i]-1]!=C[i]:
    f=1
    break
if X[0]==-1:
  X[0]=1
if f==1:
  print("-1")
else:
  for i in range(M):
    if X[i]==-1:
      X[i]=0
  for i in range(M):
    T=T+str(X[i])
  if int(T)==0:
    print("-1")
  else:
    print(T)