## https://yukicoder.me/problems/no/1924 def solve(S, index_array, p_set, p): has_p = False array = [] prev = False for i in index_array: if S[i] == p: has_p = True prev = False else: if not prev: array.append([i]) prev = True else: array[-1].append(i) ans = 0 if has_p: ans += 1 for ar in array: min_ans = float("inf") for r in ("R", "G", "B"): if r not in p_set: p_set.add(r) a = solve(S, ar, p_set, r) p_set.remove(r) min_ans = min(min_ans, a) ans += min_ans return ans def main(): N = int(input()) S = input() p_set = set() index_array = [i for i in range(N)] answer = float("inf") for p in ("R", "G", "B"): p_set.add(p) ans = solve(S, index_array, p_set, p) p_set.remove(p) answer = min(answer, ans) print(answer) if __name__ == "__main__": main()