N, M = map(int, input().split())
SCs = [list(map(int, input().split())) for i in range(M)]
S = [s for s,c in SCs] 

def main():
    ze = [-1] * N
    for s, c in SCs:
        if ze[s-1] != -1 and c != ze[s-1]:
            print(-1)
            return
        ze[s-1] = c
    
    ze = [0 if z == -1 else z for z in ze]
    
    if ze[0] == 0:
        if N == 1:
            print(0)
        else:
            print(-1)    
        return

    print("".join([str(i) for i in ze]))

main()