N,M = map(int,input().split())
lst = [0] * N
ans = 10**9
flag = False
for i in range(M):
  s,c = map(int,input().split())
  if (lst[s-1] == 0 or lst[s-1] == c):
    lst[s-1] = c
  else:
    flag = True
    break
if (lst[0] != 0 and flag == False):
  str_lst = list((map(str,lst)))
  print(''.join(str_lst))
else:
  print(-1)