#include <bits/stdc++.h>
using namespace std;
string s[3];
int main() {
  while (cin >> s[0] >> s[1] >> s[2]) {
    if (s[0] == s[1] && s[1] == s[2]) {
      puts("0");
    } else if (s[0] == s[1] || s[0] == s[2] || s[1] == s[2]) {
      puts("1");
    } else {
      int cntm = 0, cntp = 0, cnts = 0;
      for (int i = 0; i < 3; i++) {
        if (s[i][1] == 'm')
          cntm++;
        else if (s[i][1] == 'p')
          cntp++;
        else
          cnts++;
      }
      if (cntm == 3 || cntp == 3 || cnts == 3) {
        sort(s, s + 3);
        int lx = 0;
        if (abs(s[0][0] - s[1][0]) == 1) lx++;
        if (abs(s[1][0] - s[2][0]) == 1) lx++;
        if (lx)
          printf("%d\n", 2 - lx);
        else {
          if (abs(s[0][0] - s[1][0]) == 2) lx++;
          if (abs(s[1][0] - s[2][0]) == 2) lx++;
          puts(lx ? "1" : "2");
        }
      } else if (cntm == 1 && cntp == 1 && cnts == 1) {
        puts("2");
      } else {
        char c = 'm';
        if (cntp == 2)
          c = 'p';
        else if (cnts == 2)
          c = 's';
        vector<string> vs;
        for (int i = 0; i < 3; i++) {
          if (s[i][1] == c) vs.push_back(s[i]);
        }
        if (abs(vs[0][0] - vs[1][0]) <= 2) {
          puts("1");
        } else {
          puts("2");
        }
      }
    }
  }
}
