def main():
    n, m = map(int, input().split())
    sc_list = [list(input().split()) for _ in range(m)]
    li = ["-1"] * n
    for s, c in sc_list:
        s = int(s)
        if li[s - 1] != "-1" and li[s - 1] != c:
            print(-1)
            return
        li[s - 1] = c
    for i in range(n):
        if li[i] == "-1":
            li[i] = "0"
    ans = str(int("".join(li)))
    if len(ans) < n:
        print(-1)
        return
    print(ans)
main()