/*-------------icalFikr's template v2.1--------------*/
#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <algorithm>
#include <iomanip>
#include <cstddef>
#include <cassert>
#include <cctype>
#include <utility>
#include <ctime>
#ifndef GEDEBUG
#define DEBUG printf(__VA_ARGS__)
#define DEBUGS puts("gukguk")
#define TIME() printf("\nFinished in %.3lf s\n",clock()/(double)CLOCKS_PER_SEC)
#else
#define DEBUG
#define DEBUGS
#define TIME()
#endif
#ifdef __WIN32__
char getchar_unlocked() { return getchar(); }
#endif
/* Abbreviations */
#define puf push_front
#define pof pop_front()
#define pub push_back
#define pob pop_back()
#define fs first
#define sc second
#define mp make_pair
#define FOR(i,a,b) for(int i=int(a),_b=int(b);i<=_b;i++)
#define FORINC(i,a,b,inc) for(int i=int(a),_b=int(b);i<=_b;i+=inc)
#define FORLL(i,a,b) for(LL i=LL(a),_b=LL(b);i<=_b;i++)
#define FORD(i,a,b) for(int i=int(a),_b=int(b);i>=_b;i--)
#define FOREACH(i,a) for (__typeof(a.begin()) i=a.begin();i!=a.end();i++)
#define OPEN freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define CLOSE fclose(stdin); fclose(stdout);
#define ALL(v) (v).begin(),(v).end()
#define sz size()
#define reset(x,N) memset(x,N,sizeof(x))
#define nl puts("")
#define gc getchar_unlocked()
using namespace std;
typedef double db;
typedef long long LL;
typedef pair <int,int> ii;
typedef pair <LL,LL> pll;
typedef vector <ii> vii;
typedef vector <int> vint;
const db EPS = 0.0000001;
const db PI = acos(-1);
const LL INFLL = 0x7FFFFFFFFFFFFFFF;
const int INF = 0x7FFFFFFF;
template<typename T>
inline void next(T &num) {
char c; num=0;
do { c=gc; }
while (c!=EOF && c==' ' && c=='\n' && c=='\t');
int sign=(c=='-' ? -1 : 1);
if (c!='-') num+=(c-'0');
while ( (c=gc)!=EOF && c!='\n' && c!='\t' && c!=' ') {
num*=10; num+=(c-'0');
}
num*=sign;
}
inline string getstr() {
string str; char k;
while( (k=gc)==' ' || k=='\n' ) {
k=gc;
if ( k==' ' || k=='\n' ) continue;
else break;
}
str.pub(k);
while((k=gc)!=EOF &&k!='\n' && k!='\t'
&& k!='\v' && k!='\0' && k!=' ')
str.pub(k);
return str;
}
/*-------------end of template-------------*/
char c[400];
int st[6][6], cnt[6][6], h, v, n;
int _hash(char x) {
switch (x) {
case 'R' : return 0;
case 'G' : return 1;
case 'B' : return 2;
case 'Y' : return 3;
case 'W' : return 4;
}
}
int main() {
//ios_base::sync_with_stdio(0);
scanf("%d\n",&n);
gets(c);
if (!c[0]) gets(c);
for(int i = 0, m = strlen(c); i < m; i += 3 )
st[_hash(c[i])][c[i+1]-'1'] = 2;
FOR(i,0,4) {
int meme = 0;
FOR(j,0,4)
if (st[i][j]) meme = 1;
v += meme;
}
FOR(j,0,4) {
int meme = 0;
FOR(i,0,4)
if (st[i][j]) meme = 1;
h += meme;
}
int ans = INF;
FOR(msk, 0, (1<<10)-1) {
memcpy(cnt,st,sizeof st);
if (v > 1) {
FOR(i,0,4)
if ((1<<(i+5)) & msk)
FOR(j,0,4)
cnt[i][j]--;
}
if (h > 1) {
FOR(j,0,4)
if ((1<<j) & msk)
FOR(i,0,4)
cnt[i][j]--;
}
int banjir = 0;
FOR(i,0,4)
FOR(j,0,4)
banjir += (cnt[i][j] > 1);
if (banjir > 1) continue;
bool stat = 1;
for(int i = 0; i < 5; ++i) {
if (!stat) break;
banjir = 0;
for(int j = 0; j < 5; ++j)
if (cnt[i][j] == 1)
banjir++;
stat = (banjir < 2);
}
for(int j = 0; j < 5; ++j) {
if (!stat) break;
banjir = 0;
for(int i = 0; i < 5; ++i)
if (cnt[i][j] == 1)
banjir++;
stat = (banjir < 2);
}
//cout << msk / 32 << ' ' << msk % 32 << endl;
if (stat)
ans = min(ans, __builtin_popcount(msk));
}
printf("%d\n",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AgICBzdHIucHViKGspOwogICAgcmV0dXJuIHN0cjsKfQoKLyotLS0tLS0tLS0tLS0tZW5kIG9mIHRlbXBsYXRlLS0tLS0tLS0tLS0tLSovCmNoYXIgY1s0MDBdOwppbnQgc3RbNl1bNl0sIGNudFs2XVs2XSwgaCwgdiwgbjsKCmludCBfaGFzaChjaGFyIHgpIHsKICAgIHN3aXRjaCAoeCkgewogICAgICAgIGNhc2UgJ1InIDogcmV0dXJuIDA7CiAgICAgICAgY2FzZSAnRycgOiByZXR1cm4gMTsKICAgICAgICBjYXNlICdCJyA6IHJldHVybiAyOwogICAgICAgIGNhc2UgJ1knIDogcmV0dXJuIDM7CiAgICAgICAgY2FzZSAnVycgOiByZXR1cm4gNDsKICAgIH0KfQoKaW50IG1haW4oKSB7CiAgICAvL2lvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBzY2FuZigiJWRcbiIsJm4pOwogICAgZ2V0cyhjKTsKICAgIGlmICghY1swXSkgZ2V0cyhjKTsKICAgIAogICAgZm9yKGludCBpID0gMCwgbSA9IHN0cmxlbihjKTsgaSA8IG07IGkgKz0gMyApIAogICAgICAgIHN0W19oYXNoKGNbaV0pXVtjW2krMV0tJzEnXSA9IDI7CiAgICAKICAgIEZPUihpLDAsNCkgewogICAgICAgIGludCBtZW1lID0gMDsKICAgICAgICBGT1IoaiwwLDQpCiAgICAgICAgICAgIGlmIChzdFtpXVtqXSkgbWVtZSA9IDE7CiAgICAgICAgdiArPSBtZW1lOwogICAgfQogICAgCiAgICBGT1IoaiwwLDQpIHsKICAgICAgICBpbnQgbWVtZSA9IDA7CiAgICAgICAgRk9SKGksMCw0KQogICAgICAgICAgICBpZiAoc3RbaV1bal0pIG1lbWUgPSAxOwogICAgICAgIGggKz0gbWVtZTsKICAgIH0KICAgIAogICAgaW50IGFucyA9IElORjsKICAgIEZPUihtc2ssIDAsICgxPDwxMCktMSkgewogICAgICAgIG1lbWNweShjbnQsc3Qsc2l6ZW9mIHN0KTsKICAgICAgICAKICAgICAgICBpZiAodiA+IDEpIHsKICAgICAgICAgICAgRk9SKGksMCw0KQogICAgICAgICAgICBpZiAoKDE8PChpKzUpKSAmIG1zaykKICAgICAgICAgICAgICAgIEZPUihqLDAsNCkKICAgICAgICAgICAgICAgICAgICBjbnRbaV1bal0tLTsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgaWYgKGggPiAxKSB7CiAgICAgICAgICAgIEZPUihqLDAsNCkKICAgICAgICAgICAgaWYgKCgxPDxqKSAmIG1zaykKICAgICAgICAgICAgICAgIEZPUihpLDAsNCkKICAgICAgICAgICAgICAgICAgICBjbnRbaV1bal0tLTsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgaW50IGJhbmppciA9IDA7CiAgICAgICAgRk9SKGksMCw0KQogICAgICAgICAgICBGT1IoaiwwLDQpCiAgICAgICAgICAgICAgICBiYW5qaXIgKz0gKGNudFtpXVtqXSA+IDEpOwogICAgICAgIAogICAgICAgIGlmIChiYW5qaXIgPiAxKSBjb250aW51ZTsKICAgICAgICAKICAgICAgICBib29sIHN0YXQgPSAxOwogICAgICAgICAgICAKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgNTsgKytpKSB7CiAgICAgICAgICAgIGlmICghc3RhdCkgYnJlYWs7CiAgICAgICAgICAgIGJhbmppciA9IDA7CiAgICAgICAgICAgIGZvcihpbnQgaiA9IDA7IGogPCA1OyArK2opCiAgICAgICAgICAgIGlmIChjbnRbaV1bal0gPT0gMSkKICAgICAgICAgICAgICAgIGJhbmppcisrOwogICAgICAgICAgICBzdGF0ID0gKGJhbmppciA8IDIpOwogICAgICAgIH0KICAgICAgICAKICAgICAgICBmb3IoaW50IGogPSAwOyBqIDwgNTsgKytqKSB7CiAgICAgICAgICAgIGlmICghc3RhdCkgYnJlYWs7CiAgICAgICAgICAgIGJhbmppciA9IDA7CiAgICAgICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCA1OyArK2kpCiAgICAgICAgICAgIGlmIChjbnRbaV1bal0gPT0gMSkKICAgICAgICAgICAgICAgIGJhbmppcisrOwogICAgICAgICAgICBzdGF0ID0gKGJhbmppciA8IDIpOwogICAgICAgIH0KICAgICAgICAKICAgICAgICAvL2NvdXQgPDwgbXNrIC8gMzIgPDwgJyAnIDw8IG1zayAlIDMyIDw8IGVuZGw7CiAgICAgICAgaWYgKHN0YXQpCiAgICAgICAgICAgIGFucyA9IG1pbihhbnMsIF9fYnVpbHRpbl9wb3Bjb3VudChtc2spKTsKICAgIH0KICAgIAogICAgcHJpbnRmKCIlZFxuIixhbnMpOwogICAgcmV0dXJuIDA7Cn0=