You are given a string S consisting only of characters 'a' and 'b'. In one operation, you may change any character: 'a' → 'b' or 'b' → 'a'. Return the minimum number of operations required so that the string does not contain three identical consecutive characters.