N, M = map(int, raw_input().split())

ans = ""
for i in range(N):
     ans = ans + "a"

ans = list(ans)
flag = True

for i in range(M):
     s, c = map(int, raw_input().split())
     if ans[s-1] == "a":
          ans[s-1] = c
     elif ans[s-1] != c:
          flag = False

new = ""
for i in range(N):
     if ans[i] == "a":
          new = new+"0"
     else:
          new = new + str(ans[i])

if new[0] == "0":
     flag = False

if flag == True:
     print new
else:
     print "-1"
