N, M = map(int, input().split())
sc = list(list(map(int, input().split())) for _ in range(M))

def func(N,M,sc):
    ans = [0]*N
    for i in range(M):
        s = sc[i][0]-1
        c = sc[i][1]
        if c == 0:
            c = 'x'
        if ans[s] == 0 or ans[s] == c:
            ans[s] = c
        else:
            return -1
    for i in range(N):
        if ans[i] == 'x':
            ans[i] = 0
    if N != 1 and ans[0] == 0:
        return -1
    return int(''.join(map(str,ans)))

print(func(N,M,sc))