# coding: utf-8


def solve(*args: str) -> str:
    n, m = map(int, args[0].split())
    SC = [tuple(map(int, sc)) for sc in map(str.split, args[1:])]

    D = [None]*(n+1)

    for s, c in SC:
        if not D[s]:
            D[s] = c
        elif D[s] != c:
            return '-1'

    ret = ''
    if D[1] is None:
        D[1] = 1

    for d in D[1:]:
        ret += str(d) if d else '0'
    ret = str(int(ret))

    return ret if len(ret) == n else '-1'


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
