#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int s = 0, p = 0, m = 0, i, j, k, l;
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  if (s1 > s2) swap(s1, s2);
  if (s2 > s3) swap(s2, s3);
  if (s1 > s2) swap(s1, s2);
  if (s1 == s2 && s2 == s3) {
    cout << "0";
    return 0;
  }
  if (s1[0] + 1 == s2[0] && s2[0] + 1 == s3[0] &&
      (s1[1] == s2[1] && s2[1] == s3[1])) {
    cout << "0";
    return 0;
  }
  if (s1 == s2 || s2 == s3) {
    cout << "1";
    return 0;
  }
  if (s1[1] == s2[1] && (s1[0] + 1 == s2[0] || s1[0] + 2 == s2[0])) {
    cout << "1";
    return 0;
  }
  if (s2[1] == s3[1] && (s2[0] + 1 == s3[0] || s2[0] + 2 == s3[0])) {
    cout << "1";
    return 0;
  }
  if (s1[1] == s3[1] && (s1[0] + 1 == s3[0] || s1[0] + 2 == s3[0])) {
    cout << "1";
    return 0;
  }
  cout << "2";
  return 0;
}
