N, M = map(int, input().split())
sc = [[int(i) for i in input().split()] for j in range(M)]

num_min = 10**(N-1)
num_max = 10**N
if N > 1:
    i = num_min
else:
    i = 0
ans = -1
while i < num_max:
    num_list = []
    rem = i
    for j in range(N, 0, -1):
        num_list.append(rem // 10**(j-1))
        rem = i % 10**(j-1)
    
    found = True
    for k in range(M):
        s, c = sc[k]
        if num_list[s-1] != c:
            found = False
    
    if found:
        ans = i
        break
    else:
        i += 1

print(num_list)
print(ans)