def main(N,M,sc):
    if (N,M) == (1,0):
        print(0)
        return
    ans=[-1]*N
    for x in sc:
        if (ans[x[0]-1] != -1 and ans[x[0]-1] != x[1]) or (x[0] == 1 and x[1] == 0):
            print(-1)
            return
        else:
            ans[x[0]-1] = x[1]
    if ans[0] == -1:
        ans[0] = 1
    for i,x in enumerate(ans):
        if x == -1:
            ans[i] = 0
    print(*ans, sep='')

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