Hello. In a dataset like this I need to replace the null values of x1 with the most frequent value of x1 within the block

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte(block x1)
1 1
1 1
1 2
1 2
1 2
1 .
2 3
2 3
2 3
2 3
2 4
2 4
2 .
3 5
3 5
3 5
3 6
3 6
3 6
3 .
end

If there is a tie for the most frequent value, it is replaced with the highest value of x1. The result should be this:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte(block x1)
1 1
1 1
1 2
1 2
1 2
1 2
2 3
2 3
2 3
2 3
2 4
2 4
2 3
3 5
3 5
3 5
3 6
3 6
3 6
3 6
end
How can I do it? Thanks