n, m = map(int, input().split())

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



def solve():
    global n, m, sc
    ans = [None] * n
    for s, c in sc:
        if s > n:
            return -1
        if ans[s-1] is None:
            ans[s-1] = c
            continue
        if ans[s-1] != c:
            return -1
        if s+1 == n and c == 0:
            return -1
    ans = [x or 0 for x in ans]
    ans = list(map(str, ans))
    return ''.join(ans)

print(solve())