import sys
N,M = map(int,input().split())
if M == 0:
  print(0)
  sys.exit()
  
num = [-1]*N
for i in range(M):
  si,ci = map(int,input().split())
  if num[si-1] != -1 and ci != num[si-1]:
    print('-1')
    sys.exit()
  num[si-1] = ci
if num[0] == 0:
  print(-1)
  sys.exit()
else:
  num[0] = 1
  
for i in range(1,N):
  if num[i] == -1:
    num[i] =0
    
n = int(''.join(map(str,num)))
if len(str(n)) != N:
  print('-1')
  sys.exit()
print(n)
          