n, m = [int(i) for i in input().split()]

num = ['0']*n
l = [0]*n
b = 0
for i in range(m):
  s, c = input().split()
  s = int(s)-1
  if l[s] == 0 or num[s] == c:
    num[s] = c
    l[s] = 1
  else:
    b += 1
    break

    

if num[0] != '0':
  num = ''.join(num)
  print(int(num))
else:
  print(-1)