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


for i in range(10**(N-1),10**N,1):
    t = str(i)
    flg=True
    for j in arr:
        if t[j[0]-1] != str(j[i]):
            flg=False
            break

    if flg:
        print(i)
        exit()

print(-1)
