With base 2 the congruence holds (341 = 11·31 is a base-2 pseudoprime), but with base 3 the remainder is 56 rather than 1, which exposes the composite.
The Fermat primality test is a probabilistic criterion for an integer \(n>1\): it declares \(n\) composite if, for some base \(a\) coprime to \(n\), the power \(a^{n-1}\) is not congruent to 1 modulo \(n\).