#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string tiles[4];
  cin >> tiles[0] >> tiles[1] >> tiles[2];
  sort(tiles, tiles + 3);
  map<string, int> k;
  map<char, vector<int> > s;
  for (int i = 0; i < 3; ++i)
    k[tiles[i]]++, s[tiles[i][1]].push_back(tiles[i][0] - '0');
  int mx = -1;
  for (auto tl : k) mx = max(mx, tl.second);
  int mn = 10, cards;
  for (auto tl : s) {
    if (tl.second.size() == 1) cards = 2;
    if (tl.second.size() == 2) {
      int dif = tl.second[1] - tl.second[0];
      if (dif == 1 || dif == 2)
        cards = 1;
      else
        cards = 2;
    }
    if (tl.second.size() == 3) {
      int dif1 = tl.second[1] - tl.second[0];
      int dif2 = tl.second[2] - tl.second[1];
      if (dif1 == 1 && dif2 == 1)
        cards = 0;
      else if ((dif1 != 1 && dif2 == 1) || (dif1 == 1 && dif2 != 1))
        cards = 1;
      else if ((dif1 != 1 && dif2 == 2) || (dif1 == 2 && dif2 != 1))
        cards = 1;
      else
        cards = 2;
    }
    mn = min(mn, cards);
  }
  cout << min(3 - mx, mn) << "\n";
  return 0;
}
