def solve():
    N, M = map(int, input().split())
        
    d = {}
    for i in range(M):
        s, c = map(int, input().split())
        if (s in d and d[s] != c) or (s == 1 and c == 0):
            return -1
        else:
            d[s] = c
    
    ans = [0] * N
    for key, val in d.items():
        ans[key - 1] = val

    if ans[0] == 0:
        ans[0] = 1
    ans = [str(c) for c in ans]

    return "".join(ans)

print(solve())