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

sc.sort(key=lambda x: x[0])
ans = []
for i in range(10**n):
    c = 0
    i = str(i)
    if len(i) != n:
        continue
    for j in sc:
        if i[j[0]-1] == str(j[1]):
            c += 1
    if c == n:
        ans.append(i)

if len(ans) != 0:
    print(min(ans))
else:
    print(-1)