n,m = map(int,input().split())
ans = [0]*n
for _ in range(m):
    s,c = map(int,input().split())
    if ans[s-1] == 0:
        ans[s-1] = c
    elif ans[s-1] != 0 and ans[s-1] == c:
        pass
    elif ans[s-1] != 0 and ans[s-1] != c:
        print(-1)
        exit()
if n == 1:
  print(*ans)
elif n != 1 and ans[0] == 0:
    ans[0] = 1
    ans = map(str,ans)
    ans = "".join(ans)
    print(ans)
else:
    ans = map(str,ans)
    ans = "".join(ans)
    print(ans)