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

d = {}
check = False
for i in range(M):
    s, c = list(input().split())
    if s not in d:
        d[s] = c
    else:
        if d[s] != c:
            check = True

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

print(-1 if check else ans)
