#include <bits/stdc++.h>
using namespace std;
int primes[] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37,
                41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89};
string alpha = "abcdefghijklmnopqrstuvwxyz";
signed main() {
  string s[3];
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s[0] >> s[1] >> s[2];
  swap(s[0][0], s[0][1]);
  swap(s[1][0], s[1][1]);
  swap(s[2][0], s[2][1]);
  sort(s, s + 3);
  swap(s[0][0], s[0][1]);
  swap(s[1][0], s[1][1]);
  swap(s[2][0], s[2][1]);
  int IDENTICAL = 0, MAXIDENTICAL = 0, folo = 0, MAXFOLOING = 0, special = 3;
  for (int i = 1; i < 3; i++) {
    if (s[i] == s[i - 1]) {
      IDENTICAL++;
      MAXIDENTICAL = max(MAXIDENTICAL, IDENTICAL);
    } else {
      IDENTICAL = 0;
    }
    if (s[i][1] == s[i - 1][1] and char(int(s[i - 1][0]) + 1) == s[i][0]) {
      folo++;
      MAXFOLOING = max(MAXFOLOING, folo);
    } else {
      folo = 0;
    }
    if (s[i][1] == s[i - 1][1] && char(int(s[i - 1][0]) + 2) == s[i][0]) {
      special = 1;
    }
  }
  MAXIDENTICAL = 2 - MAXIDENTICAL;
  MAXFOLOING = 2 - MAXFOLOING;
  int ans = min(MAXIDENTICAL, MAXFOLOING);
  ans = min(ans, special);
  cout << ans;
  cout << "\n";
  return 0;
}
