def main():
    n, m = map(int, input().split())
    sc_list = [tuple(map(int, input().split())) for _ in range(m)]
    if n > 1:
        if (1, 0) in sc_list:
            print(-1)
            return
    elif n == 1:
        if set(sc_list) == {(1, 0)}:
            print(0)
            return
    ans = []
    for i in range(10 ** (n - 1), 10 ** n):
        tmp = str(i)
        if all([tmp[s - 1] == str(c) for s, c in sc_list]):
            ans.append(i)
    if not ans:
        print(-1)
    else:
        print(min(ans))
main()