import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = list(map(int, sys.stdin.readline().split()))
    lines = [line.rstrip() for line in sys.stdin.readlines()]

    rangeList = []
    min = 0 if N == 0 else pow(10, N - 1)
    max = 10 if N == 0 else pow(10, N)
    for n in range(min, max):
        rangeList.append(n)

    targ = ["0"] * N
    for line in lines:
        s, c = map(int, line.split())
        if s > N:
            continue
        targ[s - 1] = str(c)

    targ = int("".join(targ))

    print(targ if targ in rangeList else -1)


if __name__ == '__main__':
    main()
