N, M = map(int, input().split())

l = []
for i in range(M):
    s, c = list(input().split())
    if [s, c] not in l:
        l.append([s, c])

ans = -1
for i in range(10**(N-1), 10**N):
    num = str(i)
    count = 0
    for k in l:
        if num[int(k[0])-1] != k[1]:
            break
        else:
            count += 1
    if count == len(l):
        ans = num
        break

print(ans)
