#include <bits/stdc++.h>
using namespace std;
int k, ans;
int a[4];
string s1, s2, s3;
map<string, int> fix;
int main() {
  cin >> s1 >> s2 >> s3;
  fix[s1]++;
  fix[s2]++;
  fix[s3]++;
  ans = min(min((3 - fix[s2]), (3 - fix[s3])), (3 - fix[s1]));
  if (s1[1] == s2[1] && s1[1] == s3[1]) {
    a[1] = s1[0];
    a[2] = s2[0];
    a[3] = s3[0];
    sort(a + 1, a + 3 + 1);
    if (a[2] - a[1] == 1 && a[3] - a[2] == 1) {
      cout << 0 << endl;
      return 0;
    }
    if (abs(int(s1[0]) - int(s2[0])) == 2 || abs(int(s1[0]) - int(s2[0])) == 1)
      ans = min(ans, 1);
    if (abs(int(s1[0]) - int(s3[0])) == 2 || abs(int(s1[0]) - int(s3[0])) == 1)
      ans = min(ans, 1);
    if (abs(int(s3[0]) - int(s2[0])) == 2 || abs(int(s3[0]) - int(s2[0])) == 1)
      ans = min(ans, 1);
    cout << ans << endl;
    return 0;
  }
  if (s1[1] == s2[1]) {
    if (abs(int(s1[0]) - int(s2[0])) == 2 || abs(int(s1[0]) - int(s2[0])) == 1)
      ans = min(ans, 1);
    cout << ans << endl;
    return 0;
  }
  if (s1[1] == s3[1]) {
    if (abs(int(s1[0]) - int(s3[0])) == 2 || abs(int(s1[0]) - int(s3[0])) == 1)
      ans = min(ans, 1);
    cout << ans << endl;
    return 0;
  }
  if (s2[1] == s3[1]) {
    if (abs(int(s2[0]) - int(s3[0])) == 2 || abs(int(s2[0]) - int(s3[0])) == 1)
      ans = min(ans, 1);
    cout << ans << endl;
    return 0;
  }
  cout << ans << endl;
}
