n, m = map(int, input().split())
s_list = []
c_list = []
for a in range(m):
  s,c = map(int, input().split())
  s_list.append(s)
  c_list.append(c)
list = []
for i in range(n):
  list.append(0)

for i in range(m):
  for j in range(m):
    if ((s_list[i] == s_list[j]) and (c_list[i] != c_list[j])) or ((s_list[i] == 1) and (c_list[i] == 0)):
      print(-1)
      quit()
	
    list[s_list[i]-1] = c_list[i]

l = len(list)
ans = 0
for i in range(l):
  ans = ans + list[i]*10**(l-1-i)
  
print(ans)
