n,m=map(int,input().split())
if n==1:
  if m==0:
    print(0)
    exit()
  Q=[]
  for i in range(m):
    _,q=map(int,input().split())
    Q.append(q)
  if len(set(Q)) in [2,3,4,5,6,7]:
    print(-1)
    exit()
  print(min(Q))
  exit()

A=[[1,2,3,4,5,6,7,8,9]]+ [[0,1,2,3,4,5,6,7,8,9]]*(n-1)
for i in range(m):
  k,q=map(int,input().split())
  if k==1 and q==0:
    print(-1)
    exit()
  if not q in A[k-1]:
    print(-1)
    exit()
          
  A[k-1]=[q]
for i in range(n):
  A[i]=min(A[i])
ans=""
for i in range(n):
  ans+=str(A[i])
print(ans)
n,m=map(int,input().split())
if n==1:
  Q=[]
  for i in range(m):
    _,q=map(int,input().split())
    Q.append(q)
  if len(set(Q))!=1:
    print(-1)
    exit()
  print(min(Q))
  exit()

A=[[1,2,3,4,5,6,7,8,9]]+ [[0,1,2,3,4,5,6,7,8,9]]*(n-1)
for i in range(m):
  k,q=map(int,input().split())
  if k==1 and q==0:
    print(-1)
    exit()
  if not q in A[k-1]:
    print(-1)
    exit()
          
  A[k-1]=[q]
for i in range(n):
  A[i]=min(A[i])
ans=""
for i in range(n):
  ans+=str(A[i])
print(ans)
