def main(n, m, s_c):
    p = [0 for _ in range(n)]

    for s, c in s_c:
        if c == 0:
            if n == 3 and s == 1:
                print(-1)
                return
            elif n == 2 and s == 1:
                print(-1)
                return

        if p[s - 1] == 0 or p[s - 1] == c:
            p[s - 1] = c
        else:
            print(-1)
            return

    print(int("".join(map(str, p))))


if __name__ == "__main__":
    n, m = map(int, input().split())
    s_c = [list(map(int, input().split())) for _ in range(m)]

    main(n, m, s_c)
