#include <bits/stdc++.h>
using namespace std;
int main(void) {
  vector<string> s(3);
  cin >> s[0] >> s[1] >> s[2];
  reverse(s[0].begin(), s[0].end());
  reverse(s[1].begin(), s[1].end());
  reverse(s[2].begin(), s[2].end());
  sort(s.begin(), s.end());
  if (s[0] == s[1] && s[1] == s[2]) {
    cout << 0 << endl;
  } else if (s[0] == s[1] || s[1] == s[2]) {
    cout << 1 << endl;
  } else if (s[0][0] == s[1][0] && s[2][0] == s[1][0] &&
             (int)(s[2][1]) - (int)(s[0][1]) == 2) {
    cout << 0 << endl;
  } else if (s[0][0] == s[1][0] && (int)(s[1][1]) - (int)(s[0][1]) <= 2) {
    cout << 1 << endl;
  } else if (s[1][0] == s[2][0] && (int)(s[2][1]) - (int)(s[1][1]) <= 2) {
    cout << 1 << endl;
  } else {
    cout << 2 << endl;
  }
  return 0;
}
