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

ans = -1
for i in range(10**(n-1), 10**n):
    ili = [int(x) for x in list(str(i))]
    continue_loop = False
    for j in range(m):
        if ili[scli[j][0]-1] != scli[j][1]:
            continue_loop = True
            break
    if continue_loop:
        continue
    else:
        ans = i
        break

print(ans)