n, m = map(int, input().split())
digitslist = []
for i in range(m):
  dstr = list(input().split())
  digitslist.append(dstr)
digit = ['0'] * n
for j in digitslist:
  digit[int(j[0]) - 1] = j[1]
if digit[0] == '0':
  if len(digit) != 1:
    print('-1')
  else:
    print('0')
else:
  digitint = "".join(digit)
  print(digitint)