Three mice found a pile of peanuts and agreed to divide them equally the next day. On the second day, the first mouse arrived first. He found that the peanuts could not be divided equally, so he ate one, and the rest could be divided into three. took his own. The second and third mice came one after another. When they encountered the same problem, they also took the same method. They all ate one peanut, divided it into three parts, and took one part. So how many kernels are there at least in this pile of peanuts?
有三只老鼠发现一堆花生米，商量好第二天来平分，第二天，第一只老鼠最早来到，他发现花生无法平分，就吃了一颗，余下的恰好可以分成3份，他拿了自己的一份．第二只，第三只老鼠随后依次来到，遇到同样的问题，也取了同样的方法，都是吃掉一粒后，把花生米分成三份，拿走其中的一份．那么这堆花生米至少有几粒？
<gadget id="calculator">1 * 3</gadget>
<output>3</output>

<gadget id="calculator">3 + 1</gadget>
<output>4</output>

<gadget id="calculator">4 * 3</gadget>
<output>12</output>

<gadget id="calculator">12 + 1</gadget>
<output>13</output>

<gadget id="calculator">13 * 3</gadget>
<output>39</output>

<gadget id="calculator">39 + 1</gadget>
<output>40</output>

<result>40</result>