N, M = map(int, input().split())
sclist = [[]]*M
number = ['0']*N
judge = True
written = ['0']*N
for m in range(M):
  sclist[m] = list(map(int, input().split()))
  if written[sclist[m][0]-1] == '0':
    number[sclist[m][0]-1] = str(sclist[m][1])
    written[sclist[m][0]-1] = '1'
  elif written[sclist[m][0]-1] == '1' and number[sclist[m][0]-1] != str(sclist[m][1]):
    judge = False
  if sclist[m][0] == 1 and sclist[m][1] == 0:
    judge = False
if judge:
  if number[0] == '0':
    number[0] = '1'
  print(''.join(number))
else:
  print('-1')