#include <string>
#include <vector>
#include <iostream>
#include <cmath>
#include <climits>
static std::vector<int> redPosition;
static std::vector<int> greenPosition;
static std::vector<int> yellowPosition;
static std::vector<int> countLeftRed;
static std::vector<int> countLeftGreen;
static std::vector<int> countLeftYellow;
static int redSize;
static int greenSize;
static int yellowSize;
static int wholeSize;
struct Key {
	int position, red, green, yellow, last;
	bool operator<(const Key& other) const {
		if (position == other.position) {
			if (red == other.red) {
				if (green == other.green) {
					if (yellow == other.yellow) {
						return last < other.last;
					}
					else {
						return yellow < other.yellow;
					}
				}
				else {
					return green < other.green;
				}
			}
			else {
				return red < other.red;
			}
		}
		else {
			return position < other.position;
		}
	}
	bool operator==(const Key& other) const {
		return position == other.position && red == other.red && green == other.green && yellow == other.yellow && last == other.last;
	}
};
static std::vector < std::vector<std::vector<std::vector<int>>>> memo;
int solve(const int position, const int red, const int green, const int yellow, const int last) {
	if (position == wholeSize && red == redSize && green == greenSize && yellow == yellowSize) return 0;
	if (red > redSize || green > greenSize || yellow > yellowSize || wholeSize - position + 1 < (redSize - red) * 2 || wholeSize - position + 1 < (greenSize - green) * 2 || wholeSize - position + 1 < (yellowSize - yellow) * 2) return INT_MAX >> 1;
	if (last < 3 && memo[red][green][yellow][last] >= 0) return memo[red][green][yellow][last];
	int result = INT_MAX;
	switch (last) {
	case 0:
		if (green != greenSize) result = std::min(result, solve(position + 1, red, green + 1, yellow, 1) + std::max(countLeftRed[greenPosition[green]] - red, 0) + std::max(countLeftYellow[greenPosition[green]] - yellow, 0));
		if (yellow != yellowSize) result = std::min(result, solve(position + 1, red, green, yellow + 1, 2) + std::max(countLeftRed[yellowPosition[yellow]] - red, 0) + std::max(countLeftGreen[yellowPosition[yellow]] - green, 0));
		break;
	case 1:
		if (red != redSize) result = solve(position + 1, red + 1, green, yellow, 0) + std::max(countLeftGreen[redPosition[red]] - green, 0) + std::max(countLeftYellow[redPosition[red]] - yellow, 0);
		if (yellow != yellowSize) result = std::min(result, solve(position + 1, red, green, yellow + 1, 2) + std::max(countLeftRed[yellowPosition[yellow]] - red, 0) + std::max(countLeftGreen[yellowPosition[yellow]] - green, 0));
		break;
	case 2:
		if (red != redSize) result = solve(position + 1, red + 1, green, yellow, 0) + std::max(countLeftGreen[redPosition[red]] - green, 0) + std::max(countLeftYellow[redPosition[red]] - yellow, 0);
		if (green != greenSize) result = std::min(result, solve(position + 1, red, green + 1, yellow, 1) + std::max(countLeftRed[greenPosition[green]] - red, 0) + std::max(countLeftYellow[greenPosition[green]] - yellow, 0));
		break;
	default:
		if (red != redSize) result = solve(position + 1, red + 1, green, yellow, 0) + std::max(countLeftGreen[redPosition[red]] - green, 0) + std::max(countLeftYellow[redPosition[red]] - yellow, 0);
		if (green != greenSize) result = std::min(result, solve(position + 1, red, green + 1, yellow, 1) + std::max(countLeftRed[greenPosition[green]] - red, 0) + std::max(countLeftYellow[greenPosition[green]] - yellow, 0));
		if (yellow != yellowSize) result = std::min(result, solve(position + 1, red, green, yellow + 1, 2) + std::max(countLeftRed[yellowPosition[yellow]] - red, 0) + std::max(countLeftGreen[yellowPosition[yellow]] - green, 0));
	}
	if (last == 3) return result;
	return memo[red][green][yellow][last] = result;
}
int solve(const std::string& state) {
	countLeftRed = countLeftGreen = countLeftYellow = std::vector<int>(state.size(), 0);
	for (auto i = 0; i < state.size(); ++i) {
		switch (state[i]) {
		case 'R': redPosition.push_back(i); countLeftRed[i] = 1; break;
		case 'G': greenPosition.push_back(i); countLeftGreen[i] = 1; break;
		case 'Y': yellowPosition.push_back(i); countLeftYellow[i] = 1;  break;
		default: break;
		}
		if (i != 0) {
			countLeftRed[i] += countLeftRed[i - 1];
			countLeftGreen[i] += countLeftGreen[i - 1];
			countLeftYellow[i] += countLeftYellow[i - 1];
		}
	}
	redSize = redPosition.size();
	greenSize = greenPosition.size();
	yellowSize = yellowPosition.size();
	wholeSize = state.size();
	if (redSize * 2 > wholeSize + 1 || greenSize * 2 > wholeSize + 1 || yellowSize * 2 > wholeSize + 1) return -1;
	memo = std::vector<std::vector<std::vector<std::vector<int>>>>(redSize + 1, std::vector<std::vector<std::vector<int>>>(greenSize + 1, std::vector<std::vector<int>>(yellowSize + 1, std::vector<int>(3, -1))));
	return solve(0, 0, 0, 0, 3);
}
int main() {
	int n; std::cin >> n; std::string str; std::cin >> str;
	std::cout << solve(str) << std::endl;
}


Measured memory_bytes: 137332