n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]

seen = []
list_1 = [ x  for x in sc if x  not in seen and not seen.append(x)]

flag = [0]*n
ans = [0]*n
err = False
num = ''
for i in range(len(list_1)):
  if flag[list_1[i][0] - 1] == 0:
    ans[list_1[i][0] - 1] = list_1[i][1]
    flag[list_1[i][0] - 1] += 1
  else:
    err = True
if n>1 and ans[0] == 0:
  err = True
if err == False:
  for i in range(n):
    num += str(ans[i])
else:
  num = -1
  
print(num)