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

for i in range(1, 1000):
    number_str = str(i)
    if len(number_str) == N:
        for j in range(M):
            if number_str[sc[j][0]-1] == str(sc[j][1]):
                pass
            else:
                break
        else:
            print(i)
            break
else:
    print(-1)