#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;

int max_score;
void func(vector<int>v, int score) {
max_score = max(max_score, score);

int flag = 0;
for (int i = 2; i < 15; i++) {
if (v[i] >= 4) {//v[i]中存的是数字为i的牌的数量，比如v[13]=4就表示k有4张
v[i] -= 4; //把这四张拿出来
func(v, score + 5);
v[i] += 4;//回溯
}
}//选取有四张的牌

for (int i = 2; i < 15; i++) {
if (v[i] >= 3) {
v[i] -= 3;
func(v, score + 4);
v[i] += 3;//回溯

}
}//选取有三张的牌

for(int i=2;i<11;i++){
if (v[i] >= 1 && v[i + 1] >= 1 && v[i + 2] >= 1 && v[i + 3] >= 1 && v[i + 4] >= 1){
v[i] -= 1;
v[i+1] -= 1;
v[i+2] -= 1;
v[i+3] -= 1;
v[i+4] -= 1;
func(v, score + 3);
v[i] += 1;//回溯
v[i + 1] += 1;
v[i + 2] += 1;
v[i + 3] += 1;
v[i + 4] += 1;
}
}//选取顺子

for (int i = 2; i < 15; i++) {
if (v[i] >= 2) {
v[i] -= 2;
func(v, score + 2);
v[i] += 2;//回溯
}
}//取对子
}

int main() {
vector<int>v(15, 0);
int n;
while (cin >> n) {
for (int i = 0; i < n; i++) {
string temp;
cin >> temp;
if (temp.size() == 3) {
v[10]++;
}
else if (temp[0] == 'J') {//大小王存在0和1
if (temp[1] == '1') {
v[0]++;
}
else {
v[1]++;
}
}
else {
int pos = temp[1] - '0';
v[pos]++;
}
}
func(v, 0);
if (v[0] == 1 && v[1] == 1) { //找大小王
max_score += 5;
}
cout << max_score << endl;
}
}