N,M = map(int, input().split())
candidate = [-1]*N
flag = False
if N == 1:
  if M == 0:
    candidate = [0]
  else:
    s_temp,c_temp = map(int, input().split())
    candidate = [c_temp]
else:
  for i in range(M):
    s_temp,c_temp = map(int, input().split())
    s_temp = s_temp - 1
    if candidate[s_temp] == -1:
      candidate[s_temp] = c_temp
    elif candidate[s_temp] == c_temp:
      pass
    elif candidate[s_temp] != c_temp:
      flag = True
      break
if flag == True:
  print(-1)
else:
  candidate = [0 if i == -1 else i for i in candidate]
  print(int("".join(map(str, candidate))))