You are given two binary strings and of length . The current string is initially . Positions are numbered from to .
In one operation, choose an index with that has not been chosen before. Set to . If , also replace with . All other positions stay the same.
Find the minimum number of operations needed to obtain , or determine that it is impossible.
For each test case, output the minimum number of operations, or -1 if the target is impossible.
Choose indices and in that order, giving .
The initial string has no , so no operation is possible.
Choose indices and , giving .
Choosing indices gives .