n, m = map(int,input().split())
ans = [-1] * n
flag = 1

for i in range(m):
  s, c = map(int,input().split())
  if ans[s-1] == -1 or ans[s-1] == c:
    ans[s-1] = c
  else: #同じ桁に複数の条件が重複するのはだめ
    flag = 0

if ans[0:n-1].count(0) == n-1: #最後の桁以外全部0はだめ
  flag = 0

if flag == 0:
  print(-1)
else:
  for s in ans:
    if s == -1:
      s = 0
    print(s, end ="")