def solve(N, M, sc):
    ans = 0
    digits = [0] * N
    for s, c in sc:
        _digits = N - s
        if digits[_digits] == 0:
            digits[_digits] = c
        elif digits[_digits] != c:
            ans = -1
            break

    if digits[-1] == 0 and N > 1:
        ans = -1

    if ans != -1:
        ans = sum([digits[i] * (10 ** i) for i in range(N)])

    print(ans)


if __name__ == '__main__':
    N, M = map(int, input().split())
    sc = []
    for _ in range(M):
        sc.append(tuple(map(int, input().split())))
    solve(N, M, sc)
