#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool read(T &x) {
  int c = getchar();
  int sgn = 1;
  while (~c && c<'0' | c> '9') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  x *= sgn;
  return ~c;
}
const long long N = 5005;
const long long MOD = 1e9 + 7;
long long ara[N];
int main() {
  string s, s2, s3;
  cin >> s >> s2 >> s3;
  reverse(s.begin(), s.end());
  reverse(s2.begin(), s2.end());
  reverse(s3.begin(), s3.end());
  ara[0] = s[1] - '0';
  ara[1] = s2[1] - '0';
  ara[2] = s3[1] - '0';
  sort(ara, ara + 3);
  if (s == s2 && s2 == s3) return cout << 0, 0;
  if (s[0] == s2[0] && s[0] == s3[0]) {
    if (ara[1] - ara[0] == 1 && ara[2] - ara[1] == 1) return cout << 0, 0;
  }
  if (s[0] == s2[0]) {
    if (s == s2) return cout << 1, 0;
    long long x = s[1] - '0';
    long long y = s2[1] - '0';
    if (abs(x - y) <= 2) return cout << 1, 0;
  }
  if (s[0] == s3[0]) {
    if (s == s3) return cout << 1, 0;
    long long x = s[1] - '0';
    long long y = s3[1] - '0';
    if (abs(x - y) <= 2) return cout << 1, 0;
  }
  if (s2[0] == s3[0]) {
    if (s2 == s3) return cout << 1, 0;
    long long x = s2[1] - '0';
    long long y = s3[1] - '0';
    if (abs(x - y) <= 2) return cout << 1, 0;
  }
  cout << 2 << endl;
}
