The missing variable
Eventually, one villager, named Dan, finds an appropriate number X. He tells everybody else that the number 12345, combined with the timestamp, the reference number, and the transactions return the output number, 0031993. As regards the rule, this number is a valid output because it starts with two leading zeros.
Because it is very easy to find the output when you know the input, every other villager can verify that number X, 12345, is a correct data that return a valid hash, that is, for the mathematical problem to be solved.
Once everyone has verified that 12345 is the correct number X (the nonce) that returns the output number 0031993 (the hash value) that respects the rule, Dan is allowed to display his first page on the wall, hence becoming the reference page: