#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  char x = '1';
  char y[3] = {'m', 'p', 's'};
  map<string, int> ump;
  for (int i = 0; i < 3; i++) {
    string make = "";
    make += y[i];
    for (int j = 1; j <= 9; j++) {
      make = (char)(j + '0') + make;
      ump[make] = 0;
      make = y[i];
    }
    x = '1';
  }
  ump[a]++;
  ump[b]++;
  ump[c]++;
  for (auto uj : ump) {
    if (uj.second == 3) {
      cout << "0" << endl;
      exit(0);
    }
  }
  for (int i = 1; i <= 9; i++) {
    if (i > 7) break;
    string make = "";
    make += (char)(i + '0');
    string make1 = "";
    make1 += (char)(i + 1 + '0');
    string make2 = "";
    make2 += (char)(i + 2 + '0');
    for (int j = 0; j < 3; j++) {
      make += y[j];
      make1 += y[j];
      make2 += y[j];
      if (ump[make] && ump[make1] && ump[make2]) {
        cout << "0" << endl;
        exit(0);
      }
      make = (char)(i + '0');
      make1 = (char)(i + 1 + '0');
      make2 = (char)(i + 2 + '0');
    }
  }
  int ans = min(3 - ump[a], 3 - ump[b]);
  ans = min(ans, 3 - ump[c]);
  int ans2 = INT_MAX;
  for (int i = 1; i <= 9; i++) {
    if (i > 7) break;
    string make = "";
    make += (char)(i + '0');
    string make1 = "";
    make1 += (char)(i + 1 + '0');
    string make2 = "";
    make2 += (char)(i + 2 + '0');
    for (int j = 0; j < 3; j++) {
      make += y[j];
      make1 += y[j];
      make2 += y[j];
      int zz = 0;
      if (ump[make]) zz++;
      if (ump[make1]) zz++;
      if (ump[make2]) zz++;
      ans2 = min(3 - zz, ans2);
      make = (char)(i + '0');
      make1 = (char)(i + 1 + '0');
      make2 = (char)(i + 2 + '0');
    }
  }
  cout << min(ans, ans2) << endl;
}
