def resolve():
    def main():
        N, M = map(int, input().split())
        S, C = [0] * M, [0] * M

        if N == 1 and M == 0:
            return 0
        elif N == 2 and M == 0:
            return 10
        elif N == 3 and M == 0:
            return 100

        for i in range(M):
            S[i], C[i] = map(int, input().split())
            if i == 0:
                diction = {S[i]: C[i]}
            else:
                if S[i] not in diction.keys():
                    diction[S[i]] = C[i]
                elif diction[S[i]] != C[i]:
                    return -1

        ans = [0] * N
        for i, j in diction.items():
            ans[i - 1] = j

        if N >= 2 and ans[0] == 0:
            return -1
        else:
            return ans

    val = main()
    try:
        int(val)
        print(val)
    except:
        for i in val:
            print(i, end='')
        print()


resolve()