n, m = map(int, input().split())
s = ['0'] * m
c = ['0'] * m

for i in range(m):
    s[i], c[i] = map(int, input().split())

flg = [0] * n
ans = [0] * n

for i in range(m):
    if flg[s[i]-1] == 0:
        ans[s[i]-1] = c[i]
        flg[s[i]-1] = 1
    elif flg[s[i]-1] != 0 and ans[s[i]-1] != c[i]:
        print(-1)
        exit()
    elif flg[s[i]-1] != 0 and ans[s[i]-1] == c[i]:
        pass

if len(ans) > 1 and ans[0] == 0:
    print(-1)
    exit()

flg_str = [str(i) for i in flg]
ans_str = [str(i) for i in ans]

print(''.join(flg_str))
print(''.join(ans_str))