#include <iostream>
#include <string>
using namespace std;
int canWin(string hand) {
int count[128] = {0};
for (char c : hand) {
count[c]++;
}
int res = 0;
for (char c = '1'; c <= '9'; c++) {
if (count[c] < 4) {
count[c]++;
bool win = true;
for (char i = '1'; i <= '9'; i++) {
if (count[i] >= 3) {
count[i] -= 3;
}
else if (count[i] == 2) {
count[i] -= 2;
}
else if (count[i] == 1) {
count[i]--;
}
else {
win = false;
break;
}
}
for (char i = '1'; i <= '9'; i++) {
if (count[i] % 2 != 0) {
win = false;
break;
}
}
string yaoji = "19zESWN";
for (char y : yaoji) {
if (count[y] == 0) {
win = false;
break;
}
}
if (win) {
res++;
}
count[c]--;
}
}
return res;
}
int main() {
string hand;
cin >> hand;
int result = canWin(hand);
cout << result << endl;
return 0;
}