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


for i in range(1000):
    t = str(i)
    if len(t) != N:
        continue
    flg=True
    for item in arr:
        if t[item[0]-1] != str(item[i]):
            flg=False
            break

    if flg:
        print(i)
        exit()

print(-1)
