#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> v1, v2, v3;
  string s;
  string a[3];
  for (int i = 0; i < 3; i++) {
    cin >> s;
    a[i] = s;
    if (s[1] == 's') {
      v1.push_back(int(s[0]) - 48);
    }
    if (s[1] == 'p') {
      v2.push_back(int(s[0]) - 48);
    }
    if (s[1] == 'm') {
      v3.push_back(int(s[0]) - 48);
    }
  }
  int eqcount = 1;
  for (int i = 0; i < 2; i++) {
    if (a[i] == a[i + 1]) {
      eqcount++;
    }
  }
  if (eqcount == 3) {
    cout << "0";
    exit(0);
  }
  if ((a[0] == a[1]) || a[1] == a[2] || a[2] == a[0]) {
    eqcount = 2;
    cout << "1";
    exit(0);
  }
  if (eqcount == 1) {
    int eqcount2 = 0;
    if (v1.size() > 1) {
      sort(v1.begin(), v1.end());
      for (int i = 0; i < v1.size() - 1; i++) {
        if (v1[i + 1] - v1[i] == 1) {
          eqcount2++;
        } else if (v1[i + 1] - v1[i] == 2) {
          cout << "1";
          exit(0);
        }
      }
      cout << 2 - eqcount2;
      exit(0);
    }
    if (v2.size() > 1) {
      sort(v2.begin(), v2.end());
      for (int i = 0; i < v2.size() - 1; i++) {
        if (v2[i + 1] - v2[i] == 1) {
          eqcount2++;
        } else if (v2[i + 1] - v2[i] == 2) {
          cout << "1";
          exit(0);
        }
      }
      cout << 2 - eqcount2;
      exit(0);
    }
    if (v3.size() > 1) {
      sort(v3.begin(), v3.end());
      for (int i = 0; i < v3.size() - 1; i++) {
        if (v3[i + 1] - v3[i] == 1) {
          eqcount2++;
        } else if (v3[i + 1] - v3[i] == 2) {
          cout << "1";
          exit(0);
        }
      }
      cout << 2 - eqcount2;
      exit(0);
    }
  }
  cout << "2";
  return 0;
}
