#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int inf = 1e9 + 1;
const int prime_100000000 = 5761460;
const double eps = 1e-15;
const double EPS = 1e-9;
const double PI = acos(-1.0);
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  string a, b, c;
  cin >> a >> b >> c;
  vector<string> l;
  swap(a[0], a[1]);
  swap(b[0], b[1]);
  swap(c[0], c[1]);
  l.push_back(a);
  l.push_back(b);
  l.push_back(c);
  sort(l.begin(), l.end());
  swap(a[0], a[1]);
  swap(b[0], b[1]);
  swap(c[0], c[1]);
  if ((a[0] == b[0] && b[0] == c[0] && a[1] == b[1] && b[1] == c[1]) ||
      (l[0][0] == l[1][0] && l[1][0] == l[2][0] &&
       (int)l[0][1] == (int)l[1][1] - 1 && (int)l[1][1] == (int)l[2][1] - 1)) {
    cout << 0;
    return 0;
  }
  if (a[0] == b[0] && a[1] == b[1] || b[0] == c[0] && b[1] == c[1] ||
      a[0] == c[0] && a[1] == c[1]) {
    cout << 1;
    return 0;
  }
  if (l[0][0] == l[1][0]) {
    if (abs((int)l[0][1] - (int)l[1][1]) <= 2) {
      cout << 1;
      return 0;
    }
  }
  if (l[1][0] == l[2][0]) {
    if (abs((int)l[2][1] - (int)l[1][1]) <= 2) {
      cout << 1;
      return 0;
    }
  }
  cout << 2;
  return 0;
}
