N,M = list(map(int, input().split()))
consumed = {}
for i in range(M):
    s,c = list(map(int, input().split()))

    if s == 1 and c == 0 and N != 1:
        print(-1)
        exit()

    if s in consumed:
        if consumed[s] != c:
            print(-1)
            exit()

    consumed[s] = c

print(int(''.join([str(consumed.get(i,1)) for i in range(1,N+1)])))
