#include <bits/stdc++.h>
using namespace std;
bitset<65000000> f;
long long m[200995];
vector<long long> z;
map<long long, long long> u;
map<long long, long long> u1;
map<string, int> v;
string w[200008];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long t, c, d, e, i, j[4000], k, n;
  string a, b, x;
  cin >> a >> b >> x;
  j[a[1] - '0']++;
  j[b[1] - '0']++;
  j[x[1] - '0']++;
  c = a[0] + b[0] + (x[0] - '0') - '0' - '0';
  if (j['s' - '0'] == 3 || j['m' - '0'] == 3 || j['p' - '0'] == 3) {
    k = max(max((a[0] - '0'), (b[0] - '0')), (x[0] - '0'));
    n = min(min((a[0] - '0'), (b[0] - '0')), (x[0] - '0'));
    c = c - (k + n);
    if ((k == n && n == c) || (k == c + 1 && k == n + 2))
      cout << "0" << endl;
    else if (k - n < 3 || c - n < 3 || k - c < 3)
      cout << "1" << endl;
    else
      cout << "2" << endl;
  } else if (j['s' - '0'] == 2 || j['m' - '0'] == 2 || j['p' - '0'] == 2) {
    if (a[1] == b[1] && abs(a[0] - b[0]) < 3)
      cout << "1" << endl;
    else if (a[1] == x[1] && abs(a[0] - x[0]) < 3)
      cout << "1" << endl;
    else if (x[1] == b[1] && abs(x[0] - b[0]) < 3)
      cout << "1" << endl;
    else
      cout << "2" << endl;
  } else
    cout << "2" << endl;
  return 0;
}
