n,m = map(int,input().split())
s_c_list = []
for i in range(m):
  s_c_list.append(list(map(int,input().split())))
check = False

for i in range(10**n-1,10**n):
  counter = 0
  list_i = list(str(i))
  for j in range(m):
    if list_i[s_c_list[j][0] - 1] == s_c_list[j][1]:
      counter += 1
  if counter ==m:
    print(i)
    check = True
if check == False:
  print(-1)