n, m = map(int, input().split())

sc =[list(map(int, input().split())) for i in range(m)]
"""
sc=[]
for i in range(m):
    sc.append(list(map(int, input().split())))
"""
ans = -1
for i in range(10**n):
    j = str(i)
    if j == n and all(j[s-1] == str(t) for s, t in sc):
        ans = i
        break

print(ans)
