def resolve():
    N, M = map(int, input().split())

    checked = [False] * N
    ans = ['0'] * N

    for i in range(M):
        ss, cc = input().split()
        index = int(ss) - 1

        if checked[index] and ans[index] != cc:
            print(-1)
            return

        ans[index] = cc
        checked[index] = True

    ans = int(''.join(ans))

    if N == len(list(str(ans))):
        print(ans)
        return

    print(-1)

resolve()