n, m = map(int, input().split())
sc = [input().split() for _ in range(m)]

ans = -1
for i in range(10**n):
    x = str(i)
    if len(x) != n:
        continue
    for j in range(m):
        s, c = sc[j]
        s = int(s)
        if x[s-1] != c:
            break
    else:
        ans = i
        break
print(ans)