N,M=map(int, input().split())

s = []
c = []
for i in range(M):
    a, b = map(int, input().split())
    s.append(a)
    c.append(b)
#print(s)
#print(c)
A=[0]*N
flag=1
if s[0]==0:
  flag=0
else:
  for i in range(M):
    if A[s[i]-1]!=0 and A[s[i]-1]!=c[i]:
      flag=0
    else:
      A[s[i]-1]=c[i]

if flag==1:
  for i in range(N):
    print(A[i],end='')
else:
  print(-1)
