#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<string> v;
  for (int i = 0; i < 3; i++) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  vector<string> so;
  vector<string> po;
  vector<string> mo;
  for (int i = 0; i < v.size(); i++) {
    if (v[i][1] == 's')
      so.push_back(v[i]);
    else if (v[i][1] == 'p')
      po.push_back(v[i]);
    else if (v[i][1] == 'm')
      mo.push_back(v[i]);
  }
  sort(so.begin(), so.end());
  sort(po.begin(), po.end());
  sort(mo.begin(), mo.end());
  if (v[0] == v[1] && v[1] == v[2])
    cout << 0 << endl;
  else if (v[0] == v[1] || v[0] == v[2] || v[1] == v[2])
    cout << 1 << endl;
  else if (so.size() == 3) {
    int m1 = (so[2][0] - '0') - (so[1][0] - '0');
    int m2 = (so[1][0] - '0') - (so[0][0] - '0');
    if (m1 == 1 && m2 == 1)
      cout << "0" << endl;
    else if (m1 <= 2 || m2 <= 2)
      cout << "1" << endl;
    else
      cout << "2" << endl;
  } else if (mo.size() == 3) {
    int m1 = (mo[2][0] - '0') - (mo[1][0] - '0');
    int m2 = (mo[1][0] - '0') - (mo[0][0] - '0');
    if (m1 == 1 && m2 == 1)
      cout << "0" << endl;
    else if (m1 <= 2 || m2 <= 2)
      cout << "1" << endl;
    else
      cout << "2" << endl;
  } else if (po.size() == 3) {
    int m1 = (po[2][0] - '0') - (po[1][0] - '0');
    int m2 = (po[1][0] - '0') - (po[0][0] - '0');
    if (m1 == 1 && m2 == 1)
      cout << "0" << endl;
    else if (m1 <= 2 || m2 <= 2)
      cout << "1" << endl;
    else
      cout << "2" << endl;
  } else if (so.size() == 2) {
    int m1 = (so[1][0] - '0') - (so[0][0] - '0');
    if (m1 == 1 || m1 == 2)
      cout << "1" << endl;
    else
      cout << "2\n";
  } else if (mo.size() == 2) {
    int m1 = (mo[1][0] - '0') - (mo[0][0] - '0');
    if (m1 == 1 || m1 == 2)
      cout << "1" << endl;
    else
      cout << "2\n";
  } else if (po.size() == 2) {
    int m1 = (po[1][0] - '0') - (po[0][0] - '0');
    if (m1 == 1 || m1 == 2)
      cout << "1" << endl;
    else
      cout << "2\n";
  } else
    cout << "2\n";
  return 0;
}
