def solution():
    n, m = map(int, input().split())
    ans = [-1 for i in range(n)]
    for i in range(m):
        s, c = map(int, input().split())
        if s == 1 and c == 0 and n > 1:
            print('-1')
            return
        if ans[s-1] == -1:
            ans[s-1] = c
        elif ans[s-1] != c:
            print('-1')
            return
    ans = [str(i) if i != -1 else str(0) for i in ans]
    anss = ''
    for s in ans:
        anss = anss + s
    print(anss)

solution()
