#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  if (s1 == s2 && s2 == s3) {
    cout << "0";
    return 0;
  } else if (s1 == s2 || s1 == s3 || s2 == s3) {
    cout << "1";
    return 0;
  }
  int a = s1[0] - '0', b = s2[0] - '0', c = s3[0] - '0';
  char x = s1[1], y = s2[1], z = s3[1];
  if (x == y && x == z) {
    int k = min(a, min(b, c));
    int l = max(a, max(b, c));
    if ((a + b + c) * 2 == (min(a, min(b, c)) + max(a, max(b, c))) * 3 &&
        k == l - 2) {
      cout << "0";
    } else if (abs(a - b) == 1)
      cout << "1";
    else if (abs(c - b) == 1)
      cout << "1";
    else if (abs(a - c) == 1)
      cout << "1";
    else if (abs(a - c) == 2 || abs(a - b) == 2 || abs(b - c) == 2)
      cout << "1";
    else
      cout << "2";
  } else if (x == y) {
    if (abs(a - b) == 1 || abs(a - b) == 2)
      cout << "1";
    else
      cout << "2";
  } else if (x == z) {
    if (abs(c - a) == 1 || abs(a - c) == 2)
      cout << "1";
    else
      cout << "2";
  } else if (y == z) {
    if (abs(c - b) == 1 || abs(c - b) == 2)
      cout << "1";
    else
      cout << "2";
  } else {
    cout << "2";
  }
  return 0;
}
