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 = [0] * N
    for s, c in SCs:
        if N < s:
            print(-1)
            return

        if ze[s-1] != 0 and c != ze[s-1]:
            print(-1)
            return
        ze[s-1] = c

    if ze[0] == 0:
        print(-1)
        return

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


main()