
class Solution:
    def solve(self, N: int, M: int, s, c):

        answer = ["."] * N

        for i in range(M):

            if answer[s[i]-1] == str(c[i]):
                continue
            elif answer[s[i]-1] == ".":
                answer[s[i]-1] = str(c[i])
            else:
                return -1

        if answer[0] == "0":
            return -1
        else:
            if answer[0] == ".":
                answer[0] = "1"
            return "".join(answer).replace(".", "0")


if __name__ == '__main__':

    # standard input
    N, M = map(int, input().split())

    s, c = [], []
    for i in range(M):
        si, ci = map(int, input().split())
        s.append(si)
        c.append(ci)

    # solve
    solution = Solution()
    print(solution.solve(N, M, s, c))
