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

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

    if ze[0] is None:
        ze[0] = 1
        
    ze = [0 if z is None else z for z in ze]
    print("".join([str(i) for i in ze]))

main()