Let Ai and Bi denote the first and second move taken on the boxes marked i and i+1. Let i≤6. If Miha chooses to play Bi, then the number of tokens in the boxes marked i and i+1 is reduced by 1, the number of tokens in the box i+2 remains the same, and the number of tokens in the bag increases by 1. If Miha chooses to play the sequence of moves Ai, Ai+1, Bi+1, then the number of tokens in the box i decreases by 1, the number of tokens in the box i+1 remains the same, and the number of tokens in the box i+2 and in the bag is increased by 1. The end result is better in the second case since the only difference is that two boxes contain an extra token each. We conclude that the moves Bi for i≤6 are not profitable.
As for other moves, only B7 increases the number of tokens in the bag, so Miha should make that move as many times as possible. Without loss of generality we may assume that this move is only taken at the very end. Before that, Miha uses Ai, i≤6, to move the tokens into the seventh box which then contains 1+2+22+⋯+26=27−1=127 tokens, while the final box contains 1 token.
Let x denote the number of tokens in the seventh box at a certain point in time, and let y be the number of tokens in the last box at the same time. In order for Miha to make as many moves B7 as possible, min{x,y} has to be as large as possible. Since A7 decreases the number of tokens in the seventh box by 1 and increases the number of tokens in the last box by 2, this minimum will be the greatest when we have x≤y for the first time, so when y=x.
After k moves A7 we have x=127−k and y=1+2k. Thus, we are looking for the smallest k such that 127−k≤1+2k, or k≥3127−1=42. The smallest such k is k=42.
After 42 moves of type A7 Miha can use the B7 moves to move 127−42=85 tokens into the bag, and this is the greatest possible number of tokens that he can have in the bag at the end.