#include <bits/stdc++.h>
using namespace std;
int main() {
  int i;
  vector<int> v;
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  if (s1[1] == s2[1] && s1[1] == s3[1]) {
    v.push_back(s1[0]);
    v.push_back(s2[0]);
    v.push_back(s3[0]);
    sort(v.begin(), v.end());
    if ((v[0] + 1) == v[1] && (v[1] + 1 == v[2]))
      cout << "0";
    else if (v[0] == v[1] && v[0] == v[2])
      cout << "0";
    else if (v[0] == v[1] || v[1] == v[2])
      cout << "1";
    else if (v[0] + 1 == v[1] || v[1] + 1 == v[2] || v[0] + 2 == v[1] ||
             v[1] + 2 == v[2])
      cout << "1";
    else
      cout << "2";
  } else if (s1 == s2 || s2 == s3 || s3 == s1)
    cout << "1";
  else if (s1[1] == s2[1]) {
    if (abs(s1[0] - s2[0]) == 1 || abs(s1[0] - s2[0]) == 2)
      cout << "1";
    else
      cout << "2";
  } else if (s3[1] == s2[1]) {
    if (abs(s3[0] - s2[0]) == 1 || abs(s3[0] - s2[0]) == 2)
      cout << "1";
    else
      cout << "2";
  } else if (s1[1] == s3[1]) {
    if (abs(s1[0] - s3[0]) == 1 || abs(s1[0] - s3[0]) == 2)
      cout << "1";
    else
      cout << "2";
  } else
    cout << "2";
}
