#include <bits/stdc++.h>
using namespace std;
int minimum(int x, int y, int z) { return min(x, min(y, z)); }
int main() {
  unordered_map<char, vector<int> > m;
  unordered_map<char, vector<int> >::iterator itr;
  string a, b, c;
  cin >> a >> b >> c;
  itr = m.find(a[1]);
  if (itr == m.end()) {
    vector<int> v;
    v.push_back(a[0] - '0');
    m.insert({a[1], v});
  } else
    itr->second.push_back(a[0] - '0');
  itr = m.find(b[1]);
  if (itr == m.end()) {
    vector<int> f;
    f.push_back(b[0] - '0');
    m.insert({b[1], f});
  } else
    itr->second.push_back(b[0] - '0');
  itr = m.find(c[1]);
  if (itr == m.end()) {
    vector<int> g;
    g.push_back(c[0] - '0');
    m.insert({c[1], g});
  } else
    itr->second.push_back(c[0] - '0');
  itr = m.find('s');
  int x, y, z;
  if (itr == m.end())
    x = 3;
  else if (itr->second.size() == 1)
    x = 2;
  else if (itr->second.size() == 2) {
    if (abs(itr->second[0] - itr->second[1]) == 1 ||
        abs(itr->second[0] - itr->second[1]) == 0 ||
        abs(itr->second[0] - itr->second[1]) == 2)
      x = 1;
    else
      x = 2;
  } else {
    sort(itr->second.begin(), itr->second.end());
    if (abs(itr->second[0] - itr->second[1]) == 1 &&
            abs(itr->second[1] - itr->second[2]) == 1 ||
        (itr->second[0] == itr->second[1] && itr->second[1] == itr->second[2]))
      x = 0;
    else if (abs(itr->second[0] - itr->second[1]) == 1 ||
             abs(itr->second[1] - itr->second[2]) == 1 ||
             abs(itr->second[1] - itr->second[2]) == 2 ||
             abs(itr->second[0] - itr->second[1]) == 2 ||
             abs(itr->second[0] - itr->second[1]) == 0 ||
             abs(itr->second[1] - itr->second[2]) == 0)
      x = 1;
    else
      x = 2;
  }
  itr = m.find('m');
  if (itr == m.end())
    y = 3;
  else if (itr->second.size() == 1)
    y = 2;
  else if (itr->second.size() == 2) {
    if (abs(itr->second[0] - itr->second[1]) == 1 ||
        abs(itr->second[0] - itr->second[1]) == 0 ||
        abs(itr->second[0] - itr->second[1]) == 2)
      y = 1;
    else
      y = 2;
  } else {
    sort(itr->second.begin(), itr->second.end());
    if (abs(itr->second[0] - itr->second[1]) == 1 &&
            abs(itr->second[1] - itr->second[2]) == 1 ||
        (itr->second[0] == itr->second[1] && itr->second[1] == itr->second[2]))
      y = 0;
    else if (abs(itr->second[0] - itr->second[1]) == 1 ||
             abs(itr->second[1] - itr->second[2]) == 1 ||
             abs(itr->second[1] - itr->second[2]) == 2 ||
             abs(itr->second[0] - itr->second[1]) == 2 ||
             abs(itr->second[0] - itr->second[1]) == 0 ||
             abs(itr->second[1] - itr->second[2]) == 0)
      y = 1;
    else
      y = 2;
  }
  itr = m.find('p');
  if (itr == m.end())
    z = 3;
  else if (itr->second.size() == 1)
    z = 2;
  else if (itr->second.size() == 2) {
    if (abs(itr->second[0] - itr->second[1]) == 1 ||
        abs(itr->second[0] - itr->second[1]) == 0 ||
        abs(itr->second[0] - itr->second[1]) == 2)
      z = 1;
    else
      z = 2;
  } else {
    sort(itr->second.begin(), itr->second.end());
    if (abs(itr->second[0] - itr->second[1]) == 1 &&
            abs(itr->second[1] - itr->second[2]) == 1 ||
        (itr->second[0] == itr->second[1] && itr->second[1] == itr->second[2]))
      z = 0;
    else if (abs(itr->second[0] - itr->second[1]) == 1 ||
             abs(itr->second[1] - itr->second[2]) == 1 ||
             abs(itr->second[1] - itr->second[2]) == 2 ||
             abs(itr->second[0] - itr->second[1]) == 2 ||
             abs(itr->second[0] - itr->second[1]) == 0 ||
             abs(itr->second[1] - itr->second[2]) == 0)
      z = 1;
    else
      z = 2;
  }
  cout << minimum(x, y, z);
}
