N, M = map(int, input().split())
ans = [0] * N
for i in range(M):
  s, c = map(int, input().split())
  if [s, c] == [1, 0]:
    ans = -1
    break
  if ans[s-1] in [0, c]:
    ans[s-1] = c
  else:
    ans = -1
    break
if ans != -1:
  if ans[0] == 0:
    ans[0] = 1
  s = ""
  for i in ans:
    s += str(i)
  ans = int(s)
print(ans)