import sys

# S = input()
# N, M = map(int, input().split())
# As = [int(input()) for _ in range(N)]
# nums = list(map(int, input().split()))
# nums_2d = [list(map(int, input().split())) for _ in range(N)]


def main():
    print(solve())


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

    scs = [list(map(int, input().split())) for _ in range(M)]

    answer = '0' * N
    used = []

    for s, c in scs:
        s -= 1

        if s == N and c == 0:
            return -1

        if s in used and answer[s] != str(c):
            return -1

        used.append(s)

        answer = answer[:s] + str(c) + answer[s+1:]

    if N > 1 and answer[0] == "0":
        return -1

    return int(answer)


if __name__ == '__main__':
    main()
