N, M = map(int, input().split())
sc = []
for i in range(M):
    sp, cp = map(int, input().split())
    sc.append((sp, cp))

def solve(sc, N):
    d = {}
    for pair in sc:
        if pair[0] in d and d[pair[0]] != pair[1]:
            return -1
        elif pair[0] == 1 and pair[1] == 0: 
            return -1
        else:
            d[pair[0]] = pair[1]
    
    ans = [0] * N
    for key, val in d.items():
        ans[key - 1] = val

    for i in range(len(ans)):
        if ans[i] != 0:
            idx = i
            break
    ans = [str(c) for c in ans]

    return "".join(ans[i:])

print(solve(sc, N))